为什么我的".a"文件中的所有符号值都是 0

Why are all symbols' values in my `.a` file 0

本文关键字:符号 我的 文件 为什么      更新时间:2023-10-16

长话短说,我正在通过另一个库的构建系统构建jsoncpp(webrtc的,说是庞然大物是轻描淡写的(。这意味着我正在浏览一个我几乎无法控制且不太熟悉的构建系统。

可以说,当我在MacOS上构建libjsoncpp.a时,生成的文件工作得很好。当我在 Linux 上编译时,与生成的.a链接会导致我使用的所有内容都undefined reference。深入研究该文件,我注意到虽然MacOS版本看起来"正常",但如下所示(摘录(:

0000000000001c10 T __ZNK4Json5ValueeqERKS0_
0000000000001c00 T __ZNK4Json5ValuegeERKS0_
0000000000001bc0 T __ZNK4Json5ValuegtERKS0_
0000000000003d10 T __ZNK4Json5ValueixEPKc
0000000000003de0 T __ZNK4Json5ValueixERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE

为 Linux 构建的部分的相同部分如下所示:

0000000000000000 T _ZNK4Json5ValuegeERKS0_
0000000000000000 T _ZNK4Json5ValuegtERKS0_
0000000000000000 T _ZNK4Json5ValueixEi
0000000000000000 T _ZNK4Json5ValueixEj
0000000000000000 T _ZNK4Json5ValueixEPKc
0000000000000000 T _ZNK4Json5ValueixERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE

请注意,所有值均为零。我怀疑这是我问题的线索,但我不知道我应该从中得出什么结论。我相信我在 Linux 上构建的问题是构建系统内部某个地方的一些编译开关,知道所有零的含义可以帮助归零要查找的内容。

编辑:这与jsoncpp无关。我在使用其他库时遇到了同样的问题。我只是举了一个例子。

编辑:突破。下面是一个命令行示例,该命令行最终用于生成三个.o文件和之后的链接器命令。希望有帮助。

[3/4] ../../../src/third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/third_party/jsoncpp/jsoncpp/json_reader.o.d -DJSON_USE_EXCEPTION=0 -DV8_DEPRECATION_WARNINGS -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_X11=1 -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DOFFICIAL_BUILD -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -DCR_CLANG_REVISION="332335-1" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -DCR_LIBCXX_REVISION=332543 -DCR_LIBCXXABI_REVISION=331450 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -I../../../src/third_party/jsoncpp/source/src/lib_json -I../../../src -Igen -I../../../src/third_party/jsoncpp/overrides/include -I../../../src/third_party/jsoncpp/source/include -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -funwind-tables -fPIC -pipe -B../../../src/third_party/binutils/Linux_x64/Release/bin -pthread -fcolor-diagnostics -fmerge-all-constants -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -m64 -march=x86-64 -Wall -Wextra -Wimplicit-fallthrough -Wthread-safety -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-undefined-var-template -Wno-nonportable-include-path -Wno-address-of-packed-member -Wno-unused-lambda-capture -Wno-user-defined-warnings -Wno-enum-compare-switch -Wno-null-pointer-arithmetic -Wno-ignored-pragma-optimize -O2 -fno-ident -fdata-sections -ffunction-sections -fno-omit-frame-pointer -g2 -ggnu-pubnames -fvisibility=hidden -Xclang -load -Xclang ../../../src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang enforce-in-thirdparty-webkit -Xclang -plugin-arg-find-bad-constructs -Xclang check-enum-max-value -Xclang -plugin-arg-find-bad-constructs -Xclang check-ipc -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -std=gnu++11 -fno-exceptions -fno-rtti -nostdinc++ -isystem../../../src/buildtools/third_party/libc++/trunk/include -isystem../../../src/buildtools/third_party/libc++abi/trunk/include -fvisibility-inlines-hidden -c ../../../src/third_party/jsoncpp/overrides/src/lib_json/json_reader.cpp -o obj/third_party/jsoncpp/jsoncpp/json_reader.o
[4/4] python "../../../src/build/toolchain/gcc_ar_wrapper.py"  --output=obj/third_party/jsoncpp/libjsoncpp.a --ar="../../../src/third_party/llvm-build/Release+Asserts/bin/llvm-ar" " -r -c -s -D" @"obj/third_party/jsoncpp/libjsoncpp.a.rsp"

0值实际上没有错。据推测,它是链接时间优化的副产品。当生成最终可执行文件时,符号将看到分配的值地址(。

我的实际问题是我混合了用libc++构建的库和其他用libstdc++构建的库。未解析的符号是指将std::stringstd::unique_ptr等内容作为参数的函数。在这种情况下,libjsoncpp.a有像Json::Value(std::__1::basic_string)(一个接受字符串的构造函数(这样的符号,因为它是用 clang 构建的,并希望与 LLVM 的libc++链接,但我最终试图将最终的可执行文件与 GNU 的libstdc++链接,并且符号Json::Value(std::basic_string)尚未解决。

相关文章: