我已经成功地构建了一些boost库,但是当我将它们包含在测试项目中时,我得到了链接错误。
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : hello-jni <= test.cpp
SharedLibrary : libhello-jni.so
libboost_timer.a(cpu_timer.o): In function `~basic_iostream':
/opt/android-ndk-r7/sources/boost/../../sources/cxx-stl/gnu-libstdc++/include/istream:795: undefined reference to `VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >'
libboost_timer.a(cpu_timer.o): In function `show_time':
/opt/android-ndk-r7/sources/boost/libs/timer/src/cpu_timer.cpp:61: undefined reference to `VTT for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >'
/opt/android-ndk-r7/sources/boost/libs/timer/src/cpu_timer.cpp:61: undefined reference to `vtable for std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >'
/opt/android-ndk-r7/sources/boost/libs/timer/src/cpu_timer.cpp:61: undefined reference to `vtable for std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
libboost_timer.a(cpu_timer.o): In function `boost::timer::format(boost::timer::cpu_times const&, short, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/opt/android-ndk-r7/sources/boost/libs/timer/src/cpu_timer.cpp:177: undefined reference to `std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()'
collect2: ld returned 1 exit statusApplication.mk
APP_STL := gnustl_static
APP_CPPFLAGS = -fexceptions Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c test.cpp
LOCAL_STATIC_LIBRARIES := boost_timer, boost_system
LOCAL_LDLIBS := libboost_system.a libboost_timer.a libboost_chrono.a libboost_iostreams.a
include $(BUILD_SHARED_LIBRARY)
$(call import-module,boost) 和test.cpp
#include "test.hpp"
#include <string>
#include <boost/timer/timer.hpp>
void mytest() {
boost::timer::cpu_timer t;
}发布于 2012-06-17 00:16:40
我们有非常相似的问题。对我们有帮助的是将-lgnustl_static添加到Android.mk中LOCAL_LDLIBS行的末尾。如下所示:
LOCAL_LDIBS := -lboost_system .... -lgnustl_static我认为这是因为boost库依赖于STL,但没有静态编译它,所以需要像这样明确地提到它。
而且,您似乎不必在Application.mk中添加APP_STL := gnustl_static行。
https://stackoverflow.com/questions/8413620
复制相似问题