ld.lld的undefined symbol错误

报错

  在编译Android12的代码时,我遇到下面这个错误,提示在链接libpdfium.so时找不到以下符号:
  CPDF_StreamContentParser::~CPDF_StreamContentParser()
  CPDF_StreamContentParser::CPDF_StreamContentParser(CPDF_Document*, CPDF_Dictionary*, CPDF_Dictionary*, CFX_Matrix const*, CPDF_PageObjectHolder*, CPDF_Dictionary*, CFX_FloatRect const&, CPDF_AllStates const*, std::__1::set, std::__1::allocator >)
  CPDF_StreamContentParser::Parse(unsigned char const
, unsigned int, unsigned int, unsigned int, std::__1::vector const&)

FAILED: //external/pdfium:libpdfium link libpdfium.so
Outputs: out/soong/.intermediates/external/pdfium/libpdfium/android_arm64_armv8-a_shared/unstripped/libpdfium.so
Error: exited with code: 1
Command: prebuilts/clang/host/linux-x86/clang-r416183b1/bin/clang++ out/soong/.intermediates/bionic/libc/crtbegin_so/android_arm64_armv8-a/crtbegin_so.o @out/soong/.intermediates/external/pdfium/libpdfium/android_arm64_armv8-a_shared/unstripped/libpdfium.so.rsp -Wl,--whole-archive  out/soong/.intermediates/external/pdfium/fpdfsdk/libpdfium-fpdfsdk/android_arm64_armv8-a_static/libpdfium-fpdfsdk.a -Wl,--no-whole-archive  out/soong/.intermediates/external/pdfium/core/fpdfapi/edit/libpdfium-edit/android_arm64_armv8-a_static/libpdfium-edit.a out/soong/.intermediates/external/pdfium/fpdfsdk/formfiller/libpdfium-formfiller/android_arm64_armv8-a_static/libpdfium-formfiller.a out/soong/.intermediates/external/pdfium/core/fpdftext/libpdfium-fpdftext/android_arm64_armv8-a_static/libpdfium-fpdftext.a out/soong/.intermediates/external/pdfium/fxjs/libpdfium-fxjs/android_arm64_armv8-a_static/libpdfium-fxjs.a out/soong/.intermediates/external/pdfium/fpdfsdk/pwl/libpdfium-pwl/android_arm64_armv8-a_static/libpdfium-pwl.a out/soong/.intermediates/external/pdfium/core/fpdfdoc/libpdfium-fpdfdoc/android_arm64_armv8-a_static/libpdfium-fpdfdoc.a out/soong/.intermediates/external/pdfium/core/fpdfapi/render/libpdfium-render/android_arm64_armv8-a_static/libpdfium-render.a out/soong/.intermediates/external/pdfium/core/fpdfapi/page/libpdfium-page/android_arm64_armv8-a_static/libpdfium-page.a out/soong/.intermediates/external/pdfium/core/fpdfapi/font/libpdfium-font/android_arm64_armv8-a_static/libpdfium-font.a out/soong/.intermediates/external/pdfium/core/fpdfapi/cmaps/libpdfium-cmaps/android_arm64_armv8-a_static/libpdfium-cmaps.a out/soong/.intermediates/external/pdfium/core/fpdfapi/parser/libpdfium-parser/android_arm64_armv8-a_static/libpdfium-parser.a out/soong/.intermediates/external/pdfium/core/fdrm/libpdfium-fdrm/android_arm64_armv8-a_static/libpdfium-fdrm.a out/soong/.intermediates/external/pdfium/core/fxcodec/libpdfium-fxcodec/android_arm64_armv8-a_static/libpdfium-fxcodec.a out/soong/.intermediates/external/pdfium/third_party/libpdfium-libopenjpeg2/android_arm64_armv8-a_static/libpdfium-libopenjpeg2.a out/soong/.intermediates/external/pdfium/core/fxge/libpdfium-fxge/android_arm64_armv8-a_static/libpdfium-fxge.a out/soong/.intermediates/external/pdfium/third_party/libpdfium-agg/android_arm64_armv8-a_static/libpdfium-agg.a out/soong/.intermediates/external/pdfium/core/fxcrt/libpdfium-fxcrt/android_arm64_armv8-a_static/libpdfium-fxcrt.a out/soong/.intermediates/external/pdfium/third_party/libpdfium-skia_shared/android_arm64_armv8-a_static/libpdfium-skia_shared.a out/soong/.intermediates/external/pdfium/third_party/libpdfium-third_party-base/android_arm64_armv8-a_static/libpdfium-third_party-base.a out/soong/.intermediates/external/pdfium/third_party/libpdfium-lcms2/android_arm64_armv8-a_static/libpdfium-lcms2.a out/soong/.intermediates/external/libcxxabi/libc++demangle/android_arm64_armv8-a_static/libc++demangle.a prebuilts/clang/host/linux-x86/clang-r416183b1/lib64/clang/12.0.7/lib/linux/libclang_rt.builtins-aarch64-android.a out/soong/.intermediates/external/freetype/libft2/android_arm64_armv8-a_shared/libft2.so out/soong/.intermediates/external/icu/libicu/libicu/android_arm64_armv8-a_shared_current/libicu.so out/soong/.intermediates/external/libjpeg-turbo/libjpeg/android_arm64_armv8-a_shared/libjpeg.so out/soong/.intermediates/external/zlib/libz/android_arm64_armv8-a_shared/libz.so out/soong/.intermediates/external/libcxx/libc++/android_arm64_armv8-a_shared/libc++.so out/soong/.intermediates/bionic/libc/libc/android_arm64_armv8-a_shared_current/libc.so out/soong/.intermediates/bionic/libm/libm/android_arm64_armv8-a_shared_current/libm.so out/soong/.intermediates/bionic/libdl/libdl/android_arm64_armv8-a_shared_current/libdl.so out/soong/.intermediates/bionic/libc/crtend_so/android_arm64_armv8-a/obj/bionic/libc/arch-common/bionic/crtend_so.o -o out/soong/.intermediates/external/pdfium/libpdfium/android_arm64_armv8-a_shared/unstripped/libpdfium.so -target aarch64-linux-android10000 -Bprebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined-version -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_stripped.a -Wl,--exclude-libs,libunwind_llvm.a -Wl,--exclude-libs,libunwind.a -Wl,--icf=safe -fuse-ld=lld -Wl,--pack-dyn-relocs=android+relr -Wl,--no-undefined -Wl,--hash-style=gnu -Wl,-z,separate-code -Wl,-z,max-page-size=4096  -Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a  -nostdlib -Wl,--gc-sections -shared -Wl,-soname,libpdfium.so -Wl,-icf=all 
Output:
ld.lld: error: undefined symbol: CPDF_StreamContentParser::~CPDF_StreamContentParser()
>>> referenced by memory:2339 (external/libcxx/include/memory:2339)
>>>               cpdf_contentparser.o:(std::__1::unique_ptr >::~unique_ptr()) in archive out/soong/.intermediates/external/pdfium/core/fpdfapi/page/libpdfium-page/android_arm64_armv8-a_static/libpdfium-page.a
>>> referenced by memory:2339 (external/libcxx/include/memory:2339)
>>>               cpdf_contentparser.o:(CPDF_ContentParser::CPDF_ContentParser(CPDF_Form*, CPDF_AllStates const*, CFX_Matrix const*, CPDF_Type3Char*, std::__1::set, std::__1::allocator >*)) in archive out/soong/.intermediates/external/pdfium/core/fpdfapi/page/libpdfium-page/android_arm64_armv8-a_static/libpdfium-page.a
>>> referenced by memory:2339 (external/libcxx/include/memory:2339)
>>>               cpdf_contentparser.o:(CPDF_ContentParser::~CPDF_ContentParser()) in archive out/soong/.intermediates/external/pdfium/core/fpdfapi/page/libpdfium-page/android_arm64_armv8-a_static/libpdfium-page.a
>>> referenced 1 more times

ld.lld: error: undefined symbol: CPDF_StreamContentParser::CPDF_StreamContentParser(CPDF_Document*, CPDF_Dictionary*, CPDF_Dictionary*, CFX_Matrix const*, CPDF_PageObjectHolder*, CPDF_Dictionary*, CFX_FloatRect const&, CPDF_AllStates const*, std::__1::set, std::__1::allocator >*)
>>> referenced by ptr_util.h:56 (external/pdfium/third_party/base/ptr_util.h:56)
>>>               cpdf_contentparser.o:(CPDF_ContentParser::CPDF_ContentParser(CPDF_Form*, CPDF_AllStates const*, CFX_Matrix const*, CPDF_Type3Char*, std::__1::set, std::__1::allocator >*)) in archive out/soong/.intermediates/external/pdfium/core/fpdfapi/page/libpdfium-page/android_arm64_armv8-a_static/libpdfium-page.a
>>> referenced by ptr_util.h:56 (external/pdfium/third_party/base/ptr_util.h:56)
>>>               cpdf_contentparser.o:(CPDF_ContentParser::Parse()) in archive out/soong/.intermediates/external/pdfium/core/fpdfapi/page/libpdfium-page/android_arm64_armv8-a_static/libpdfium-page.a

ld.lld: error: undefined symbol: CPDF_StreamContentParser::Parse(unsigned char const*, unsigned int, unsigned int, unsigned int, std::__1::vector > const&)
>>> referenced by cpdf_contentparser.cpp:201 (external/pdfium/core/fpdfapi/page/cpdf_contentparser.cpp:201)
>>>               cpdf_contentparser.o:(CPDF_ContentParser::Parse()) in archive out/soong/.intermediates/external/pdfium/core/fpdfapi/page/libpdfium-page/android_arm64_armv8-a_static/libpdfium-page.a
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

分析

  这三个符号由以下的BP编译出来的libpdfium-page静态库libpdfium-page.a导出:
  /external/pdfium/core/fpdfapi/page/Android.bp
  而编译目标 libpdfium.so引用了libpdfium-page.a。

/external/pdfium/Android.bp

108 cc_library_shared {
109     name: "libpdfium",
110     defaults: ["pdfium-core"],
111 
112     header_libs: [
113         "libpdfium-constants",
114     ],
115 
116     whole_static_libs: [
117         "libpdfium-fpdfsdk",
118     ],
119 
120     // Transitivity is not supported for static libraries (yet).
121     // Lists the whole transitivity closure here.
122     static_libs: [
123         "libpdfium-agg",
124         "libpdfium-cmaps",
125         "libpdfium-edit",
126         "libpdfium-fdrm",
127         "libpdfium-font",
128         "libpdfium-formfiller",
129         "libpdfium-fpdfdoc",
130         "libpdfium-fpdftext",
131         "libpdfium-fxcodec",
132         "libpdfium-fxcrt",
133         "libpdfium-fxge",
134         "libpdfium-fxjs",
135         "libpdfium-libopenjpeg2",
136         "libpdfium-page",
137         "libpdfium-parser",
138         "libpdfium-pwl",
139         "libpdfium-render",
140         "libpdfium-skia_shared",
141         "libpdfium-third_party-base",
142         "libpdfium-lcms2",
143     ],

  先找到libpdfium-page.a确认文件有没问题。

daidaihaofei@ubuntu:~/3588_android12/3588-android12/out/soong/.intermediates/external/pdfium/core/fpdfapi/page/libpdfium-page/android_arm64_armv8-a_static$ file libpdfium-page.a
libpdfium-page.a: current ar archive

  确认是静态库文件,没问题。再打开obj目录,检查静态库包含的目标文件的正确性。
  三个符号位于cpdf_streamcontentparser.o中。经发现cpdf_streamcontentparser.o是空文件,导致链接而成的ibpdfium-page.a和libpdfium.so缺少对应的符号。

解决方法

  这个问题应该是由编译错误引起。删除掉libpdfium-page.a和对应的obj目录重新编译可以解决。

你可能感兴趣的:(编译系统,android)