c - 海湾合作委员会 : undefined reference to 'function'

标签 c gcc linker-errors undefined-reference

我在我的计算机(Ubuntu)上安装了一个名为 xx 的 C 库。 ,其头文件位于 /usr/local/include/xx/xx.h.a file.so file位于路径 /usr/local/lib 中命名libxx.alibxx.so .

测试文件:

#include<xx/xx.h>
#include<stdio.h>
int main(){
 printf("Test\n");
 call_function_declared_in_the_header_file();
 return 0;
}

当我使用gcc编译gcc test.c -o test时,出现以下错误:

/tmp/ccb7O0eh.o: In function `main':
test.c:(.text+0xa): undefined reference to `call_function_declared_in_the_header_file'
collect2: error: ld returned 1 exit status

我不知道为什么。我不太擅长C语言。那么我该如何解决这个问题呢?

最佳答案

您必须链接该库,即如果您想包含 <math.h> ( libm.so/libm.a ) 您必须链接到:

gcc program.c -o program -lm其中-lm调用链接

参见http://www.network-theory.co.uk/docs/gccintro/gccintro_17.html ,

https://www.rapidtables.com/code/linux/gcc/gcc-l.html

编译总是涉及编译器链接器

关于c - 海湾合作委员会 : undefined reference to 'function' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48138005/

相关文章:

c - 如何在C中的FreeBSD中获取进程的当前工作目录?

C : Splint pointers related warnings. 它们是什么意思?

gcc - 与 Boost.Filesystem 链接时出现问题

c++ - 什么是 undefined reference /未解析的外部符号错误以及如何修复它?

c++ - (Windows HID API)HidD_GetPreparsedData() 由于句柄不正确而在 WM_INPUT 消息处理程序中失败?

C指针恶作剧

gcc - 将 newlib 移植到交叉编译器中

realpath 函数的转换问题(C 编程)

c++ - 我如何验证重构保留了代码流,而不仅仅是行为?

c - STM32F Discovery - 对arm_sin_f32的 undefined reference