一、undefined reference
/tmp/cc7DP8ZD.o: In function `parse_number':
cJSON.c:(.text+0x48f): undefined reference to `pow'
/tmp/cc7DP8ZD.o: In function `print_number':
cJSON.c:(.text+0x5b4): undefined reference to `floor'
截图如下:
解决办法:在编译语句后加 -lm,原因是在Unix,一些数学计算并不属于Unix的标准库,就像线程一样,需要依赖额外的库
gcc -o testClient testClient.c cJSON.c poolsocket.c socketlog.c socketutil.c -I ../inc/ -lpthread -lm
截图:
二、SZ and VOID
expected ‘)’ before ‘sz’
expected ‘;’ before ‘void’
解决办法:将cJSON.h和cJSON.c分别放在头文件和源文件下即可
gcc -o testClient testClient.c cJSON.c poolsocket.c socketlog.c socketutil.c -I ../inc/ -lpthread -lm
-I ../inc/下包含所有的依赖文件
本文介绍了解决C编译过程中遇到的未定义引用错误的方法,并提供了一个具体的例子,即如何处理数学函数如pow和floor的链接问题。同时,文章还涉及了如何正确组织头文件和源文件来避免编译器语法错误。
9922

被折叠的 条评论
为什么被折叠?



