这是我在使用Android的Boost库时遇到的错误。我正在使用Android NDK r8e并提升1.53并跟随this tutorial。
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lgnustl_static
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/boost/lib//libboost_regex-gcc-mt-1_53.a(instances.o): in function boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int):/home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1508: error: undefined reference to 'std::__detail::_List_node_base::_M_transfer(std::__detail::_List_node_base*, std::__detail::_List_node_base*)'
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/boost/lib//libboost_regex-gcc-mt-1_53.a(instances.o): in function boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int):/home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1508: error: undefined reference to 'std::__detail::_List_node_base::_M_transfer(std::__detail::_List_node_base*, std::__detail::_List_node_base*)'
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/boost/lib//libboost_regex-gcc-mt-1_53.a(instances.o): in function boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int):/home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1516: error: undefined reference to 'std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
/home/tassilo/android-ndks/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: jni/boost/lib//libboost_regex-gcc-mt-1_53.a(instances.o): in function boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned int):/home/tassilo/android-ndks/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_list.h:1532: error: undefined reference to 'std::__detail::_List_node_base::_M_unhook()'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libusit.so] Error 1
这就是我的make文件的样子:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include ./jni/opencv/sdk/native/jni/OpenCV.mk
LOCAL_MODULE := usit
LOCAL_SRC_FILES := cr.cpp
LOCAL_CFLAGS += -I$(LOCAL_PATH)/boost/include/boost-1_53
LOCAL_LDLIBS += -L$(LOCAL_PATH)/boost/lib/ -lboost_system-gcc-mt-1_53 -lboost_regex-gcc-mt-1_53 -lboost_filesystem-gcc-mt-1_53 -lboost_date_time-gcc-mt-1_53 \
-L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi \
-lgnustl_static
include $(BUILD_SHARED_LIBRARY)
正如教程中所建议的,我指定了NDK Root的路径。我正在使用Ubuntu 12.04并在.bashrc和.profile中定义了NDK_ROOT变量,如下所示:
export NDK_ROOT=${HOME}/android-ndks/android-ndk-r8e
我感谢任何帮助。
编辑:
这是我的Application.mk
APP_PLATFORM := android-8
APP_ABI := armeabi-v7a
APP_OPTIM := debug
NDK_DEBUG := 1
NDK_TOOLCHAIN_VERSION := 4.6
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -frtti
答案 0 :(得分:2)
要使用 gnustl (静态或共享),您需要参数APP_STL
。通常,我们在 Application.mk 中设置它,但您也可以在命令行上设置它(小心操作,不要混用不同的值)。
我建议安装最新的NDK,而不是使用过时的4.6工具链。
Application.mk 的示例:
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION := 4.8
APP_CPPFLAGS := -std=c++11