在Android上与Boost链接错误

时间:2011-12-07 10:12:35

标签: android boost android-ndk

我已成功构建了一些boost-libraries但是当我将它们包含在测试项目中时,我会收到链接错误。

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 status

Application.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;
}

1 个答案:

答案 0 :(得分:1)

我们遇到了非常相似的问题。对我们有帮助的是在Android.mk中的LOCAL_LDLIBS行末尾添加-lgnustl_static。像这样:

LOCAL_LDIBS := -lboost_system .... -lgnustl_static

我认为这是因为boost库依赖于STL但没有静态编译,因此需要明确地提及它。

此外,您似乎无需将APP_STL := gnustl_static行添加到Application.mk