首页 > 代码库 > libjson-c库的使用问题备忘
libjson-c库的使用问题备忘
gcc -o json-demo -g json-demo.c -std=c99 -I/usr/include/json -L/usr/lib/i386-linux-gnu/ -ljson
注意:
1、json-demo和json-demo.c参数需要在前面,不能在后面,见错误1
2、需要就爱如-std=c99,代码中需要,也可以用-std=gnu99,见错误2
3、-I是json的头文件的路径
4、-L是json库所在位置,这个路径可能根据系统不同而不同,建议用find / -name "libjson*"找到位置
5、-ljson不可省略,尽量放在最后,没有这个参数会出现错误1的现象
错误1:
jack@ubuntu:~/json-c$ gcc -I/usr/include/json -L/usr/lib/i386-linux-gnu/ -ljson -std=gnu99 -o json-demo -g json-demo.c
/tmp/ccaITRtr.o: In function `GetValByKey‘:
/home/jack/json-c/json-demo.c:13: undefined reference to `json_object_object_get‘
/home/jack/json-c/json-demo.c:16: undefined reference to `json_object_get_type‘
/home/jack/json-c/json-demo.c:20: undefined reference to `json_object_get_string‘
/home/jack/json-c/json-demo.c:23: undefined reference to `json_object_get_int‘
/tmp/ccaITRtr.o: In function `main‘:
/home/jack/json-c/json-demo.c:39: undefined reference to `json_object_new_string‘
/home/jack/json-c/json-demo.c:41: undefined reference to `json_object_get_string‘
/home/jack/json-c/json-demo.c:43: undefined reference to `json_object_to_json_string‘
******
/tmp/ccaITRtr.o: In function `GetValByKey‘:
/home/jack/json-c/json-demo.c:13: undefined reference to `json_object_object_get‘
/home/jack/json-c/json-demo.c:16: undefined reference to `json_object_get_type‘
/home/jack/json-c/json-demo.c:20: undefined reference to `json_object_get_string‘
/home/jack/json-c/json-demo.c:23: undefined reference to `json_object_get_int‘
/tmp/ccaITRtr.o: In function `main‘:
/home/jack/json-c/json-demo.c:39: undefined reference to `json_object_new_string‘
/home/jack/json-c/json-demo.c:41: undefined reference to `json_object_get_string‘
/home/jack/json-c/json-demo.c:43: undefined reference to `json_object_to_json_string‘
******
错误2:没有加-std=99参数的错误
jack@ubuntu:~/json-c$ gcc -o json-demo -g json-demo.c -I/usr/include/json -L/usr/lib/i386-linux-gnu/ -ljson
json-demo.c: In function ‘main’:
json-demo.c:87:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
json-demo.c:87:2: note: use option -std=c99 or -std=gnu99 to compile your code
json-demo.c: In function ‘main’:
json-demo.c:87:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
json-demo.c:87:2: note: use option -std=c99 or -std=gnu99 to compile your code
libjson-c库的使用问题备忘
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。