为什么我会得到这个Android Studio错误:“重新编译-fPIC”?(Why am I ge

2019-11-05 05:27发布

我使用NDK 18和单独编译静态库使用x86_64的NDK独立的工具链。 我可以成功链接,但是当我尝试访问图书馆建设说这样的话时,我收到几十个错误的不平凡的路:

... requires dynamic R_X86_64_PC32 reloc against '_ZZN4seal4util21get_msb_index_genericEPmmE15deBruijnTable64' which may overflow at runtime; recompile with -fPIC

见我以前在我的构建文件的细节问题: 为什么我仍然得到链接中的Android NDK与CMake的静态库未定义引用错误?

这里继建议: 持续加-fPIC编译后旗甚至错误“与-fPIC编译”我确信与编译静态库-fPIC (和CMake的具有详细= 1,确认-fPIC使用),但我仍然得到错误。 从我可以告诉有没有办法,我编译这个共享库没有侵入它的CMake的文件。

这里一些答案: 如何用-fPIC编译建议增加-fPIC编译后直接。 我想这也没有成功。

示例输出编译静态库(确认cmake的使用-fPIC ):

Building CXX object CMakeFiles/seal.dir/seal/bigpolyarray.cpp.o
/home/user/AndroidStudioProjects/SEALApp/gen-libs/toolchains/x86_64/bin/x86_64-linux-android-clang++  -fPIC   -I/home/user/AndroidStudioProjects/SEALApp/gen-libs/seal/SEAL_2.3.1/SEAL  -fPIC -fPIE -O3 -DNDEBUG   -std=gnu++17 -o CMakeFiles/seal.dir/seal/bigpolyarray.cpp.o -c /home/user/AndroidStudioProjects/SEALApp/gen-libs/seal/SEAL_2.3.1/SEAL/seal/bigpolyarray.cpp

错误:

Build command failed.
Error while executing process /home/wyoumans/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/wyoumans/AndroidStudioProjects/SEALApp/app/.externalNativeBuild/cmake/debug/x86_64 --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/x86_64/libnative-lib.so
FAILED: : && /opt/android-ndk-r18/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=x86_64-none-linux-android21 --gcc-toolchain=/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64 --sysroot=/opt/android-ndk-r18/sysroot -fPIC -fPIC -isystem /opt/android-ndk-r18/sysroot/usr/include/x86_64-linux-android -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=gnu++1z -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /opt/android-ndk-r18/platforms/android-21/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -L/opt/android-ndk-r18/sources/cxx-stl/llvm-libc++/libs/x86_64 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/x86_64/libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o  ../../../../libs/seal/x86_64/lib/libseal.a /opt/android-ndk-r18/platforms/android-21/arch-x86_64/usr/lib64/liblog.so -latomic -lm "/opt/android-ndk-r18/sources/cxx-stl/llvm-libc++/libs/x86_64/libc++_static.a" "/opt/android-ndk-r18/sources/cxx-stl/llvm-libc++/libs/x86_64/libc++abi.a" && :
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZZN4seal4util21get_msb_index_genericEPmmE15deBruijnTable64' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTCNSt6__ndk119basic_ostringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_13basic_ostreamIcS2_EE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVNSt6__ndk119basic_ostringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVNSt6__ndk119basic_ostringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVNSt6__ndk119basic_ostringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVNSt6__ndk119basic_ostringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVNSt6__ndk115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEEE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVNSt6__ndk115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEEE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVNSt6__ndk115basic_streambufIcNS_11char_traitsIcEEEE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(bigpoly.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVNSt6__ndk115basic_streambufIcNS_11char_traitsIcEEEE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(biguint.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZZN4seal4util21get_msb_index_genericEPmmE15deBruijnTable64' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(smallmodulus.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZZN4seal4util21get_msb_index_genericEPmmE15deBruijnTable64' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(globals.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZN4seal4util16global_variables18global_memory_poolE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(hash.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZN4seal4util12HashFunction3rhoE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(mempool.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZTVN4seal4util16MemoryPoolHeadMTE' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: ../../../../libs/seal/x86_64/lib/libseal.a(uintarith.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZZN4seal4util21get_msb_index_genericEPmmE15deBruijnTable64' which may overflow at runtime; recompile with -fPIC
/opt/android-ndk-r18/toolchains/x86_64-4.9/prebuilt/linux-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: warning: shared library text segment is not shareable
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Answer 1:

你的编译步骤包括以下内容:

-fPIC -fPIE

我相信所发生的事情是,后者是压倒前者。 PIE是唯一有效的可执行文件,而不是库。

我认为-fPIE标志可能是从您的构建脚本来吗? NDK的CMake的工具链文件并追加-fPIE ,但仅限于可执行文件。



文章来源: Why am I getting this Android Studio error: “recompile with -fPIC”?