【发布时间】:2015-06-25 04:34:38
【问题描述】:
我想在我的程序中使用 json-c。编译(链接)时出现错误:
parsejson.c:(.text.startup+0xf): undefined reference to `json_object_new_object'
parsejson.c:(.text.startup+0x1c): undefined reference to `json_object_new_string'
parsejson.c:(.text.startup+0x2b): undefined reference to `json_object_new_int'
parsejson.c:(.text.startup+0x3a): undefined reference to `json_object_new_boolean'
parsejson.c:(.text.startup+0x4a): undefined reference to `json_object_new_double'
parsejson.c:(.text.startup+0x52): undefined reference to `json_object_new_array'
parsejson.c:(.text.startup+0x5f): undefined reference to `json_object_new_string'
parsejson.c:(.text.startup+0x6e): undefined reference to `json_object_new_string'
parsejson.c:(.text.startup+0x7b): undefined reference to `json_object_new_string'
parsejson.c:(.text.startup+0x8b): undefined reference to `json_object_array_add'
parsejson.c:(.text.startup+0x96): undefined reference to `json_object_array_add'
parsejson.c:(.text.startup+0xa1): undefined reference to `json_object_array_add'
parsejson.c:(.text.startup+0xb3): undefined reference to `json_object_object_add'
parsejson.c:(.text.startup+0xc3): undefined reference to `json_object_object_add'
parsejson.c:(.text.startup+0xd3): undefined reference to `json_object_object_add'
parsejson.c:(.text.startup+0xe5): undefined reference to `json_object_object_add'
parsejson.c:(.text.startup+0xf5): undefined reference to `json_object_object_add'
parsejson.c:(.text.startup+0xfd): undefined reference to `json_object_to_json_string'
我将 json-c 和我的程序放在同一个文件夹中,并使用 #include <json-c/json.h> 包含它。
【问题讨论】:
-
显示你的编译命令行。您是否在
parsejson.c或parsejson.o之后列出库,无论您在链接命令行中列出哪个?你建好 json-c 库了吗?你在链接它吗? -
不,我只是在使用命令“gcc parsejson.c”,json-c 是第三方库,但我使用#include 包含
-
标头提供声明。它通常不提供实现。您需要与需要编译和安装的库链接(取决于它是共享的还是静态的)。图书馆的自述文件没有告诉你这个吗?