首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么我的`.a`文件中所有符号的值都是0

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

Stack Overflow用户
提问于 2018-05-31 02:52:03
回答 1查看 107关注 0票数 4

长话短说,我正在通过另一个库的构建系统构建jsoncpp (webrtc的构建系统可以说是庞然大物),这意味着我正在浏览一个我几乎无法控制和熟悉的构建系统。

可以说,当我在MacOS上构建libjsoncpp.a时,生成的文件工作得非常好。当我在Linux上编译时,链接到生成的.a会导致我使用的所有东西都是undefined reference。深入到文件中,我注意到虽然MacOS版本看起来“正常”,但如下所示(摘录):

代码语言:javascript
复制
0000000000001c10 T __ZNK4Json5ValueeqERKS0_
0000000000001c00 T __ZNK4Json5ValuegeERKS0_
0000000000001bc0 T __ZNK4Json5ValuegtERKS0_
0000000000003d10 T __ZNK4Json5ValueixEPKc
0000000000003de0 T __ZNK4Json5ValueixERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE

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

代码语言:javascript
复制
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无关。我在其他lib上也遇到了同样的问题。我只是以此为例。

编辑:突破性。下面是一个命令行示例,最终用于构建一个包含三个.o文件的文件以及随后的链接器命令。希望这能有所帮助。

代码语言:javascript
复制
[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"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-31 08:22:37

实际上,值为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)未被解析。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50611621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档