gpt4 book ai didi

android - 带有 clang++ 和 libc++ 的 CrystaX 与 boost 和 icu 的链接错误

转载 作者:搜寻专家 更新时间:2023-10-31 02:21:55 26 4
gpt4 key购买 nike

我想使用 CrystaX (10.1.0) 中的 clang++-3.5 和 libc++ 来编译使用 boost + ICU(使用 boost 的 u32regex_match 等)的 native 组件。它在我的桌面机器上使用 clang++-3.5 和 libc++ 编译和链接良好。它使用 CrystaX 编译得很好,但我收到一堆“ undefined reference ”链接错误:

[powercf@powercf-desktop]computing/programming/crystax_test% rm -rf app/src/main/{obj,libs}; /home/powercf/Android/Ndk/ndk-build V=1 -C /home/powercf/computing/programming/crystax_test/app/src/main
make: Entering directory `/home/powercf/computing/programming/crystax_test/app/src/main'
rm -f ./libs/arm64-v8a/lib*.so ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/armeabi-v7a-hard/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so ./libs/x86_64/lib*.so
rm -f ./libs/arm64-v8a/gdbserver ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/armeabi-v7a-hard/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver ./libs/x86_64/gdbserver
rm -f ./libs/arm64-v8a/gdb.setup ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/armeabi-v7a-hard/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup ./libs/x86_64/gdb.setup
[armeabi] Compile++ thumb: test-boost <= test.cpp
/home/powercf/Android/crystax-ndk-10.1.0/toolchains/llvm-3.5/prebuilt/linux-x86_64/bin/clang++ -MMD -MP -MF ./obj/local/armeabi/objs/test-boost/test.o.d -gcc-toolchain /home/powercf/Android/crystax-ndk-10.1.0/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -target armv5te-none-linux-androideabi -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -I/home/powercf/Android/crystax-ndk-10.1.0/sources/boost/1.57.0/include -I/home/powercf/Android/crystax-ndk-10.1.0/sources/icu/54.1/include -I/home/powercf/Android/crystax-ndk-10.1.0/sources/icu/54.1/include -I/home/powercf/Android/crystax-ndk-10.1.0/sources/icu/54.1/include -I/home/powercf/Android/crystax-ndk-10.1.0/sources/icu/54.1/include -I/home/powercf/Android/crystax-ndk-10.1.0/sources/cxx-stl/llvm-libc++/libcxx/include -I/home/powercf/Android/crystax-ndk-10.1.0/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/include -Ijni -DANDROID -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -c -I/home/powercf/Android/crystax-ndk-10.1.0/sources/crystax/include -I/home/powercf/Android/crystax-ndk-10.1.0/platforms/android-3/arch-arm/usr/include jni/test.cpp -o ./obj/local/armeabi/objs/test-boost/test.o
[armeabi] SharedLibrary : libtest-boost.so
/home/powercf/Android/crystax-ndk-10.1.0/toolchains/llvm-3.5/prebuilt/linux-x86_64/bin/clang++ -Wl,-soname,libtest-boost.so -shared --sysroot=/home/powercf/Android/crystax-ndk-10.1.0/platforms/android-3/arch-arm ./obj/local/armeabi/objs/test-boost/test.o /home/powercf/Android/crystax-ndk-10.1.0/sources/boost/1.57.0/libs/armeabi/libboost_regex.a /home/powercf/Android/crystax-ndk-10.1.0/sources/icu/54.1/libs/armeabi/libicui18n.a /home/powercf/Android/crystax-ndk-10.1.0/sources/icu/54.1/libs/armeabi/libicuio.a /home/powercf/Android/crystax-ndk-10.1.0/sources/icu/54.1/libs/armeabi/libicuuc.a /home/powercf/Android/crystax-ndk-10.1.0/sources/icu/54.1/libs/armeabi/libicudata.a /home/powercf/Android/crystax-ndk-10.1.0/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a -lgcc -gcc-toolchain /home/powercf/Android/crystax-ndk-10.1.0/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 -no-canonical-prefixes -target armv5te-none-linux-androideabi -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -mthumb -L/home/powercf/Android/crystax-ndk-10.1.0/sources/crystax/empty /home/powercf/Android/crystax-ndk-10.1.0/sources/crystax/libs/armeabi/thumb/libcrystax.so -lc -o ./obj/local/armeabi/libtest-boost.so
/home/powercf/Android/crystax-ndk-10.1.0/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__cxa_call_unexpected' in /home/powercf/Android/crystax-ndk-10.1.0/sources/cxx-stl/llvm-libc++/libs/armeabi/thumb/libc++_static.a(cxa_personality.o) is referenced by DSO /home/powercf/Android/crystax-ndk-10.1.0/sources/crystax/libs/armeabi/thumb/libcrystax.so
/home/powercf/Android/crystax-ndk-10.1.0/sources/boost/1.57.0/libs/armeabi/libboost_regex.a(cpp_regex_traits.o):cpp_regex_traits.cpp:function boost::re_detail::cpp_regex_traits_char_layer<char>::init(): error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)'
/home/powercf/Android/crystax-ndk-10.1.0/sources/boost/1.57.0/libs/armeabi/libboost_regex.a(cpp_regex_traits.o):cpp_regex_traits.cpp:function boost::re_detail::cpp_regex_traits_char_layer<char>::init(): error: undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
/home/powercf/Android/crystax-ndk-10.1.0/sources/boost/1.57.0/libs/armeabi/libboost_regex.a(cpp_regex_traits.o):cpp_regex_traits.cpp:function boost::re_detail::cpp_regex_traits_char_layer<char>::init(): error: undefined reference to 'std::string::_M_leak_hard()'
/home/powercf/Android/crystax-ndk-10.1.0/sources/boost/1.57.0/libs/armeabi/libboost_regex.a(cpp_regex_traits.o):cpp_regex_traits.cpp:function boost::re_detail::cpp_regex_traits_char_layer<char>::init(): error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/home/powercf/Android/crystax-ndk-10.1.0/sources/boost/1.57.0/libs/armeabi/libboost_regex.a(cpp_regex_traits.o):cpp_regex_traits.cpp:function boost::re_detail::cpp_regex_traits_char_layer<char>::init(): error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
/home/powercf/Android/crystax-ndk-10.1.0/sources/boost/1.57.0/libs/armeabi/libboost_regex.a(cpp_regex_traits.o):cpp_regex_traits.cpp:function boost::re_detail::cpp_regex_traits_char_layer<char>::init(): error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'

等等等

我不是 android、NDK、boost、icu、crystaX 或 clang 专家,但我猜 CrystaX boost 和 icu 库与 clang 并不真正兼容?或者我缺少一些配置选项或其他东西?有什么方法可以使它正常工作(g++ + libstdc++ 也不适用于我使用相同的代码或 std::future 所以我没有使用它)?或者我是否需要考虑为 android 编译我自己的 boost 和 icu(我宁愿避免)?

测试.cpp:

#include <jni.h>
#include <iostream>
#include <boost/regex.hpp>
#include <boost/regex/icu.hpp>
#include <unicode/unistr.h>
#include <unicode/ustream.h>

extern "C" jlong Java_com_powercf_examples_crystax_test_MainActivity_Foobie(JNIEnv* env, jobject thiz, jstring s)
{
boost::regex regex1("hello");
std::string input_str1("test");
bool match = boost::regex_match(input_str1, regex1);

UnicodeString regex_str = "tea";
UnicodeString input_str2 = "coffee";
boost::u32regex regex2 = boost::make_u32regex(regex_str);
match = boost::u32regex_match(input_str2, regex2);

return match;
}

Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := test-boost
LOCAL_SRC_FILES := test.cpp
LOCAL_STATIC_LIBRARIES := boost_regex_static icui18n_static icuio_static icuuc_static icudata_static
LOCAL_CPP_FEATURES := rtti exceptions
include $(BUILD_SHARED_LIBRARY)

$(call import-module,boost/1.57.0)
$(call import-module,icu/54.1)

应用程序.mk:

NDK_TOOLCHAIN_VERSION := clang3.5
APP_STL := c++_static

最佳答案

发生这种情况是因为 LLVM libc++ 与 GNU libstdc++ 二进制不兼容,并且 CrystaX NDK 中的 Boost 是针对 GNU libstdc++ 构建和链接的。修复它的唯一方法是使用 LLVM libc++ 构建 Boost,这应该不会太难,但它完全未经测试。我已经提交了 ticket在 CrystaX NDK 中执行此操作,但实际上目前最快的方法是使用 GNU libstdc++ 作为 C++ 标准库实现(它适用于 clang)。

换句话说,您的 Application.mk 应该如下所示:

NDK_TOOLCHAIN_VERSION := clang3.5
APP_STL := gnustl_static

关于android - 带有 clang++ 和 libc++ 的 CrystaX 与 boost 和 icu 的链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30870938/

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