gpt4 book ai didi

android - Android NDK(libgcc_real.a)上 '__aeabi_ul2f'的多个定义

转载 作者:行者123 更新时间:2023-12-03 11:47:50 26 4
gpt4 key购买 nike

使用CMake在Android上编译大型项目时,出现关于multiple definition of '__aeabi_ul2f'的错误。显然,找到定义的地方之一是在

libsmoltcp_cpp_interface_rust.a(compiler_builtins-5ae026d08032e786.compiler_builtins.2kv22hwk-cgu.127.rcgu.o): previous definition here
这是一些Rust代码与CMake中这样编译的C++混合在一起的:
add_custom_target(
lib_smol_tcp_rust
COMMAND
echo "-------------COMPILING LIBSMOLTCP_CPP_INTERFACE RELEASE x86_64"
&& cargo build --release
&& echo "-------------COMPILING LIBSMOLTCP_CPP_INTERFACE RELEASE aarch64-linux-android"
&& cargo build --target aarch64-linux-android --release
&& echo "-------------COMPILING LIBSMOLTCP_CPP_INTERFACE RELEASE armv7-linux-androideabi"
&& cargo build --target armv7-linux-androideabi --release
&& echo "-------------COMPILING LIBSMOLTCP_CPP_INTERFACE RELEASE i686"
&& cargo build --target i686-linux-android --release
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
然后 lsmoltcp_cpp_interface_rust(这是C++代码)与使用rust 的 lib_smol_tcp_rust链接。
看起来对象 '__aeabi_ul2f'已在Android NDK项目的 libgcc_real.a上定义。
所以我不应该针对libgcc编译C++/Rust混合代码吗?我怎样才能做到这一点?我很困惑,因为我使用
整个错误:
  [1369/1369] Linking CXX shared library /home/dev/orwell/orwell_flutter_app/build/app/intermediates/cmake/debug/obj/armeabi-v7a/liborwell_android.so
FAILED: /home/dev/orwell/orwell_flutter_app/build/app/intermediates/cmake/debug/obj/armeabi-v7a/liborwell_android.so
: && /opt/android-sdk-linux/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi24 --gcc-toolchain=/opt/android-sdk-linux/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/opt/android-sdk-linux/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -std=c++17 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,liborwell_android.so -o /home/dev/orwell/orwell_flutter_app/build/app/intermediates/cmake/debug/obj/armeabi-v7a/liborwell_android.so CMakeFiles/orwell_android.dir/orwell_jni.cpp.o CMakeFiles/orwell_android.dir/DecodedFfmpegFrameJNI.cpp.o CMakeFiles/orwell_android.dir/JavaOrwellFlutterRenderer.cpp.o CMakeFiles/orwell_android.dir/MediaCodecDecoder.cpp.o CMakeFiles/orwell_android.dir/JavaSimpleFileWriter.cpp.o CMakeFiles/orwell_android.dir/JavaHashMapJNI.cpp.o CMakeFiles/orwell_android.dir/JavaFlutterEventMessenger.cpp.o _liborwell/liborwell_static.a -landroid -llog -lmediandk /home/dev/orwell/orwell_flutter_app/android/app/src/main/cpp/../../../../../../deps/ffmpeg/build/android/armeabi-v7a/lib/libavcodec.so /home/dev/orwell/orwell_flutter_app/android/app/src/main/cpp/../../../../../../deps/ffmpeg/build/android/armeabi-v7a/lib/libavutil.so /home/dev/orwell/orwell_flutter_app/android/app/src/main/cpp/../../../../../../deps/ffmpeg/build/android/armeabi-v7a/lib/libswscale.so /home/dev/orwell/orwell_flutter_app/android/app/src/main/cpp/../../../../../../deps/ffmpeg/build/android/armeabi-v7a/lib/libswresample.so /home/dev/orwell/orwell_flutter_app/build/app/intermediates/cmake/debug/obj/armeabi-v7a/libmyRtspClient.so /home/dev/orwell/orwell_flutter_app/build/app/intermediates/cmake/debug/obj/armeabi-v7a/libjrtp.so _liborwell/_myRtspClient/libmyRtspClient-static.a _liborwell/_myRtspClient/_JTRPLIB/src/libjrtp.a _liborwell/_ZLMediaKit/libzlmediakit.a _liborwell/_ZLMediaKit/libzltoolkit.a _liborwell/_ZLMediaKit/libmpeg.a _liborwell/_ZLMediaKit/libmov.a _liborwell/_ZLMediaKit/libflv.a _liborwell/common/openvpn_zl_socket/libopenvpn_zl_socket.a _liborwell/_libopenvpn3/src/libopenvpn/libopenvpn_lib.a _liborwell/_libopenvpn3/openvpn3/libssl.a _liborwell/_libopenvpn3/openvpn3/libcrypto.a _liborwell/_libopenvpn3/openvpn3/liblzo.a _liborwell/_libopenvpn3/openvpn3/liblz4.a _liborwell/_libopenvpn3/libtins/lib/libtins.a _liborwell/_libopenvpn3/smoltcp_cpp_interface/libsmoltcp_cpp_static.a /home/dev/orwell/deps/libopenvpn3/smoltcp_cpp_interface/target/armv7-linux-androideabi/release/libsmoltcp_cpp_interface_rust.a -ldl _liborwell/common/liborwellebml/liborwell_ebml.a _liborwell/_libebml/libebml.a _liborwell/common/liborwellprofile/liborwell_profile.a _liborwell/common/liborwellprofile2/liborwell_profile2.a _liborwell/common/liborwellprofile2/_protobuf/libprotobufd.a /opt/android-sdk-linux/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/libz.a -latomic -lm && :
/opt/android-sdk-linux/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /opt/android-sdk-linux/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/armv7-a/thumb/libgcc_real.a(_arm_addsubsf3.o): multiple definition of '__aeabi_ul2f'
/opt/android-sdk-linux/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /home/dev/orwell/deps/libopenvpn3/smoltcp_cpp_interface/target/armv7-linux-androideabi/release/libsmoltcp_cpp_interface_rust.a(compiler_builtins-5ae026d08032e786.compiler_builtins.2kv22hwk-cgu.127.rcgu.o): previous definition here
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.


这就是我创建Rust工具链的方式:
&& ${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm64 --install-dir /opt/RUST_NDK_TOOLCHAIN/arm64 \
&& ${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch arm --install-dir /opt/RUST_NDK_TOOLCHAIN/arm \
&& ${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py --api 26 --arch x86 --install-dir /opt/RUST_NDK_TOOLCHAIN/x86
如您所见,链接使用
--exclude-libs,libgcc_real.a
因此它根本不应该使用 libgcc_real.a,但是无论如何它还是会提示 libgcc_real.a!

最佳答案

在将Rust静态库链接到C/C++项目之前,我已经遇到了这个问题。
要使gcc无法链接libgcc很难(有时是不可能的)。它被硬编码为“默认”库,链接器将始终将其拉出(您可以尝试使用-nodefaultlibs-nostdlib来防止这种情况)。也可以从链接描述文件中提取它。
对我来说,诀窍在于链接器参数中的顺序很重要。
链接器的工作方式大致如下:

  • 所有参数从左到右处理,每个仅处理一次。
  • 对于每个非-l参数,链接器将加载给定的.a/.o并提取所有符号,如果重复则出错。如果引入的符号需要在任何地方都未定义的其他符号,则链接器会将其作为“ undefined symbol ”进行跟踪。
  • 对于每个-l参数,链接器将加载.a并仅提取与先前 undefined symbol 匹配的符号。如果.a具有已定义的符号,则将忽略它们(而不是错误!)。

  • 尝试尽早将 libsmoltcp_cpp_interface_rust.a放在链接器args中。之后的任何 -l都不会导致重复错误,因为 -l会忽略重复项。

    关于android - Android NDK(libgcc_real.a)上 '__aeabi_ul2f'的多个定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63950040/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com