c - 使用 json-c 时出现 undefined reference 错误

标签 c json json-c

我想在我的程序中使用 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> 将其包含在内.

最佳答案

静态链接时,gcc 会带来已经遇到的符号。因此,如果您在源文件之前传递 -ljson ,gcc 将获取静态库,然后最终不需要其中的任何内容。 因此,您应该将库链接到您的代码之后

虽然您还没有分享您的编译命令行所说的内容,但我建议您尝试以下操作:

$ gcc -g -v -Wall -std=gnu99 -static -L/path/to/compiled/library parsejson.c -o parsejson -ljson

关于c - 使用 json-c 时出现 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31041272/

相关文章:

python - 将 numpy.array 传递给 ctypes 但得到错误结果的问题

c - 有什么解决方案可以在原子上下文中在用户和内核之间共享数据吗?

c - 在Linux中的父子进程中使用Pipe

c++ - 数组的顺序求和返回不正确的值

JavaScript、Ajax、php parsererror 以及如何获取 post Json?

java - 使用 myBatis 从数据库读取 JSON

java - 如何让 Gson 的单转义与 Javascript 的特殊字符和符号的双转义一起使用?

如果换行,则在 char[] 数组中复制文件会崩溃

c - 在 C 项目中包含 json-c