为什么我的".a"文件中的所有符号值都是 0
Why are all symbols' values in my `.a` file 0
长话短说,我正在通过另一个库的构建系统构建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::string
或std::unique_ptr
等内容作为参数的函数。在这种情况下,libjsoncpp.a
有像Json::Value(std::__1::basic_string)
(一个接受字符串的构造函数(这样的符号,因为它是用 clang 构建的,并希望与 LLVM 的libc++
链接,但我最终试图将最终的可执行文件与 GNU 的libstdc++
链接,并且符号Json::Value(std::basic_string)
尚未解决。
- 为什么我的共享库中存在展开符号
- 将无符号字符的向量存储在数组中会给我 std::bad_alloc
- 如何返回实际值(在我的例子中是无符号字符数组)而不是来自 C++ 函数的指针?
- Clang 给了我符号更改的警告,但代码仍然产生正确的输出
- 在我的变量打印C++后无法获得 $ 打印符号
- 我无法让我的程序工作,我一直得到未定义的符号:C
- 我正在为学校开发一个小班模板实验室,我的代码无法编译,它给了我一个未解析的外部符号
- 为什么我的".a"文件中的所有符号值都是 0
- 为什么内部链接的名称会出现在我的目标文件的符号表中?
- 为什么我的函数只在我用 & 符号传递结构时才更新结构?
- 字符串流问题,我认为我的代码看起来不错,但它显示奇怪的符号
- 为什么 UMDH 找不到我的符号?我可以在没有它们的情况下解释堆栈跟踪吗?
- 我如何在我的C DLL中修复未解决的外部符号错误
- 为什么ValGrind找不到我的符号?
- 我的Py_NoneStruct符号(python,boost.python)在哪里
- 在我的嵌套 for 循环中找不到符号"k"?
- LNK2019:未解析的外部符号;我是不是忘了
- 如果我有一个固定大小的填充ascii数字的char数组,我知道它指的是一个无符号整数,那么将其转换为无符号整数的最快方法
- 为什么当我放置定点符号时,我的输出是 0.00
- 我的字节数组到十六进制字符串转换器有什么问题,或者为什么它在写入文件时会在某个位置后剪切符号?