Tag: undefined reference

用C ++编译的C代码:未定义的引用

我有一个小程序,我可以毫无困难地使用GCC和ICC编译,但我也希望代码能够与G ++和ICPC一起使用。 我试着添加这个: #ifdef __cplusplus extern “C” { #endif 在开头和这个: #ifdef __cplusplus } #endif 在所有头文件的末尾,但我仍然得到几个未定义的引用“…”错误。

这些作业之间是否有一个序列点?

以下代码中的两个赋值之间是否存在序列点: f(f(x=1,1),x=2);

gcc不会编译和运行MySQL C库

#include #include int main(int argc, char **argv) { printf(“MySQL client version: %s\n”, mysql_get_client_info()); } 〜$ gcc -o mysql-test MySQL-Test.c 我试图从终端执行此测试程序,但得到以下错误消息: /tmp/cceEmI0I.o:在函数main’: MySQL-Test.c:(.text+0xa): undefined reference to mysql_get_client_info的main’: MySQL-Test.c:(.text+0xa): undefined reference to ‘ 怎么了? 我的系统是ubuntu

C头问题:#include和“未定义引用”

好吧,我一直在尝试使用这个时间最长,我似乎无法让它正常工作。 我有三个文件, main.c , hello_world.c和hello_world.h 。 无论出于什么原因,他们似乎没有很好地编译,我真的无法弄清楚为什么…… 这是我的源文件。 首先hello_world.c: #include #include “hello_world.h” int hello_world(void) { printf(“Hello, Stack Overflow!\n”); return 0; } 然后hello_world.h,简单: int hello_world(void); 最后是main.c: #include “hello_world.h” int main() { hello_world(); return 0; } 当我把它放入GCC时,这就是我得到的: cc main.c -o main /tmp/ccSRLvFl.o:在函数`main’中: main.c :(。text + 0x5):未定义引用`hello_world’ collect2:ld返回1退出状态 make:*** [main]错误1 有人能帮帮我吗? 我真的坚持这个,但我99%肯定这是一个非常简单的修复。

使用gcc 未定义引用`__gxx_personality_v0′

可能重复: 什么是__gxx_personality_v0? 我已经在编译C ++代码的上下文中看到了这个问题。 但是我要编译纯 C代码并继续收到此错误。 我被禁止使用“-lstdc ++”作为解决此gcc问题的方法。 如何更改我的代码以使其正常工作以及为什么会出现此错误? 我的简化代码: //this is main.cpp #include int main() { char ch[3]; ch[0] = getc(stdin); ch[1] = getc(stdin); ch[2] = ‘\0’; printf(“%s\n”, ch); return 0; } 我的编译命令是: gcc main.cpp

C ++类模板未定义函数引用

当我在我的main函数中调用模板类“add”和“greater”中的两个函数时,我一直得到未定义的引用。 所以,我有:number.h #ifndef NUMBER_H #define NUMBER_H template class number { public: T x; T y; number (int a, int b){ x=a; y=b;} int add (T&); T greater (); }; #endif number.cpp #include “number.h” template int number::add (T& rezAdd){ rezAdd = x+y; return 1; } template T number::greater (){ return x>y? x : y; } 我的主文件是:resolver.cpp […]

使用信号量的未定义参考问题

我正在使用信号量,但我一直遇到未定义的参考警告,从而导致我的代码无法工作。 我从文本中提取了示例代码,但是他们的一些语法出现了问题,所以我去了POSIX的信号量教程并将其改为语法,因此我现在得到了这些参考错误。 我可能只是忽略了一些东西,但我找不到它。 错误: Producers_Consumers.c:52: warning: return type of ‘main’ is not ‘int’ /tmp/cceeOM6F.o: In function `producer’: Producers_Consumers.c:(.text+0x1e): undefined reference to `sem_init’ Producers_Consumers.c:(.text+0x3a): undefined reference to `sem_init’ Producers_Consumers.c:(.text+0x46): undefined reference to `sem_wait’ Producers_Consumers.c:(.text+0x52): undefined reference to `sem_wait’ Producers_Consumers.c:(.text+0x5e): undefined reference to `sem_post’ Producers_Consumers.c:(.text+0x6a): undefined reference to `sem_post’ /tmp/cceeOM6F.o: In function `consumer’: Producers_Consumers.c:(.text+0x7e): undefined reference to […]

为什么linux上的curses会让我出现以下错误?

试图让getch()努力捕获按键。 #include … … WINDOW *w; char f; w = initscr(); timeout(3000); f = getch(); endwin(); 给我以下错误: – undefined reference to `wgetch’ undefined reference to `stdscr’

使用头文件时未定义的符号错误

我收到了以下错误,并且不能为我的生活弄清楚我做错了什么。 $ gcc main.c -o main Undefined symbols: “_wtf”, referenced from: _main in ccu2Qr2V.o ld: symbol(s) not found collect2: ld returned 1 exit status main.c中: #include #include “wtf.h” main(){ wtf(); } wtf.h: void wtf(); wtf.c: void wtf(){ printf(“I never see the light of day.”); } 现在,如果我将整个函数包含在头文件中而不仅仅是签名中,那么它就符合要求,因此我知道wtf.h被包含在内。 为什么编译器看不到wtf.c? 或者我错过了什么? 问候。

在C编程中,编译时什么是`undefined reference`error?

我有以下简单的程序,我试图在linux ubuntu中编译。 Main.c : #include #include “Person.h” int main() { struct Person1 p1 = Person1_Constructor(10, 1000); } Person.c : #include #include “Person.h” struct Person1 Person1_Constructor(const int age, const int salary) { struct Person1 p; p.age = age; p.salary = salary; return p; }; Person.h : struct Person1 { int age, salary; }; struct Person1 Person1_Constructor(const […]