全部。
我在OpenWRT linux 发行版上使用JSON-C库时遇到问题。我在下面做了一个简单的程序来测试它。
#include <json/json.h>
int main() {
char * string = "{\"name\" : \"joys of programming\"}";
json_object * jobj = json_tokener_parse(string);
}
然后我用下面的命令编译它。
gcc test.c -o test -ljson-c
但是,我收到以下错误。
In function `main':
test.c:(.text+0x2c): undefined reference to `json_tokener_parse'
test.c:(.text+0x38): undefined reference to `json_tokener_parse'
collect2: ld returned 1 exit status
我什至用下面的命令编译它,但它仍然不起作用。
gcc -ljson-c test.c -o test
然后我尝试在编译时添加 -L 参数,但仍然没有运气。
gcc test.c -o test -L/usr/lib -ljson-c
此 OpenWRT 发行版使用opkg作为其包安装程序,这是我运行opkg install libjson-c时显示的内容。
Package libjson-c (0.11-2) installed in root is up to date.
我什至使用 -E 参数运行编译命令,以查看是否使用了正确的标头,看起来就像我可以找到方法声明json_tokener_parse 一样。我不确定我哪里出错了。我即将从 Github 进行手动安装,但我真的不想这样做,因为我还必须手动安装其他程序。有没有人有什么建议?
谢谢。