加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 07:23:22 所属栏目:百科 来源:网络整理
导读:长话短说,我正在通过另一个图书馆的构建系统构建jsoncpp(webrtc,可以说是庞然大物将是轻描淡写).这意味着我正在通过一个我无法控制的构建系统进行导航,并且不太熟悉. 我只想说,当我在MacOS上构建libjsoncpp.a时,生成的文件完全正常.当我在Linux上编译时,链接
长话短说,我正在通过另一个图书馆的构建系统构建jsoncpp(webrtc,可以说是庞然大物将是轻描淡写).这意味着我正在通过一个我无法控制的构建系统进行导航,并且不太熟悉.

我只想说,当我在MacOS上构建libjsoncpp.a时,生成的文件完全正常.当我在Linux上编译时,链接到生成的.a会导致我使用的所有内容的未定义引用.潜入文件,我注意到虽然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没有任何关系.我和其他lib一样遇到了同样的问题.我只是选择了这个例子.

编辑:突破.下面是命令行的示例,最后用于构建三个.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"

解决方法

这些值实际上没有任何问题.据推测,它是链接时优化的副产品.生成最终可执行文件时,符号将分配其值的地址.

我的实际问题是我将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)未解析.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读