有关使用cJSON包解析或者创建JSON时遇到的错误和解决办法

一、undefined reference /tmp/cc7DP8ZD.o: In function `parse_number':cJSON.c:(.te

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