首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android上的Boost出现链接错误

Android上的Boost出现链接错误
EN

Stack Overflow用户
提问于 2011-12-07 18:12:35
回答 1查看 1.6K关注 0票数 2

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

代码语言:javascript
复制
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

代码语言:javascript
复制
APP_STL := gnustl_static
APP_CPPFLAGS = -fexceptions  

Android.mk

代码语言:javascript
复制
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

代码语言:javascript
复制
#include "test.hpp"
#include <string>
#include <boost/timer/timer.hpp>

void mytest() {
boost::timer::cpu_timer t;
}
EN

回答 1

Stack Overflow用户

发布于 2012-06-17 00:16:40

我们有非常相似的问题。对我们有帮助的是将-lgnustl_static添加到Android.mk中LOCAL_LDLIBS行的末尾。如下所示:

代码语言:javascript
复制
LOCAL_LDIBS := -lboost_system .... -lgnustl_static

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

而且,您似乎不必在Application.mk中添加APP_STL := gnustl_static行。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8413620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档