一、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/下包含所有的依赖文件