CrystaX与clang ++和libc ++链接错误与boost和icu

时间:2015-06-16 14:45:53

标签: android c++ boost android-ndk icu

我想使用CrystaX(10.1.0)中的clang ++ - 3.5和libc ++编译一个使用boost + ICU的本机组件(使用boost' s u32regex_match等)。它在我的桌面计算机上使用clang ++ - 3.5和libc ++进行编译和链接。它使用CrystaX编译得很好,但是我得到了一堆未定义的引用"链接错误:

[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&)'

等。等

我不是机器人,NDK,提升,icu,crystaX或clang专家,但我猜测CrystaX提升&amp; amp; icu图书馆与clang真的不兼容吗?或者我错过了一些配置选项或什么?有没有办法让这个工作(g ++ + libstdc ++也不适合我使用相同的代码或std :: future所以我没有使用它)?或者我需要看看为Android编译我自己的boost和icu(我宁愿避免)?

TEST.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)

Application.mk:

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

1 个答案:

答案 0 :(得分:2)

这是因为LLVM libc ++与GNU libstdc ++不是二进制兼容的,而且CrystaX NDK中的Boost是针对GNU libstdc ++构建和链接的。修复它的唯一方法是使用LLVM libc ++构建Boost,这不应该太难,但它完全没有经过测试。我已经在CrystaX NDK中提交了ticket,但实际上现在最快的方法是使用GNU libstdc ++作为C ++标准库实现(它与clang一起使用)。

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

NDK_TOOLCHAIN_VERSION := clang3.5
APP_STL := gnustl_static