有很多线程有类似的问题,但许多处理 c++ 代码并有 c++ 解决方案。但是,根据我在各个线程上收集的信息,当 gcc 尝试链接库时,我可能会丢失一个库。
我不知道我需要包含哪个库才能成功构建 JSON1。
gcc -g -fPIC -dynamiclib YourCode.c -o YourCode.dylib
所以我做了:
$ gcc -g -fPIC -dynamiclib sqlite-src-3180000/ext/misc/json1.c -o json1
sqlite-src-3180000/ext/misc/json1.c:344:11: warning: implicit declaration of function
'sqlite3_value_subtype' is invalid in C99 [-Wimplicit-function-declaration]
if( sqlite3_value_subtype(pValue)==JSON_SUBTYPE ){
^
sqlite-src-3180000/ext/misc/json1.c:501:3: warning: implicit declaration of function
'sqlite3_result_subtype' is invalid in C99 [-Wimplicit-function-declaration]
sqlite3_result_subtype(pCtx, JSON_SUBTYPE);
^
2 warnings generated.
Undefined symbols for architecture x86_64:
"_sqlite3_result_subtype", referenced from:
_jsonArrayFunc in json1-5de683.o
_jsonExtractFunc in json1-5de683.o
_jsonObjectFunc in json1-5de683.o
_jsonQuoteFunc in json1-5de683.o
_jsonArrayFinal in json1-5de683.o
_jsonObjectFinal in json1-5de683.o
_jsonReturnJson in json1-5de683.o
...
"_sqlite3_value_subtype", referenced from:
_jsonAppendValue in json1-5de683.o
"_sqlite3_vsnprintf", referenced from:
_jsonPrintf in json1-5de683.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我错过了什么?
这是我的 gcc 详细信息,如果有帮助的话:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin