1

プログラムで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>.

4

3 に答える 3

1

静的にリンクする場合、gcc は既に検出されているシンボルを取得します。したがって-ljson、ソース ファイルの前に渡す場合、gcc は静的ライブラリを取得し、最終的には何も必要としません。そのため、コードの後に​​リンクするライブラリを配置する必要があります。

コンパイルコマンドラインの内容を共有していませんが、次のようなことを試すことをお勧めします:

$ gcc -g -v -Wall -std=gnu99 -static -L/path/to/compiled/library parsejson.c -o parsejson -ljson
于 2015-06-25T05:16:54.580 に答える
1

これを使用してみてください:

#include "../json-c/json.h"

コンパイラを使用すると、標準ライブラリでjson.hが検索されるためです。明らかに、標準ライブラリにはありません。私が言ったことを使用すると、コンパイラは現在のワークスペースでjson.hを検索します。

于 2016-03-11T04:52:24.640 に答える