【问题标题】:How link with static boost libraries for android?如何与android的静态boost库链接?
【发布时间】:2011-07-04 09:38:53
【问题描述】:

我在使用 Android-ndk-r5b 将 boost 库移植和链接到 android 时遇到问题。 我首先使用以下步骤构建 boost 库(没有 mpi、python):

1.注释了 boost_1_46_0\libs\thread\build 中的第 53 行:

# if [ os.name ] = "NT" { api = win32 ; }

2。在 boost 根目录下创建文件 user-config.jam

androidNDKRoot = ../android-ndk-r5b ; 使用 gcc:android4.4.3:$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-g++.exe: --sysroot=$(androidNDKRoot)/platforms/android-3/arch-arm -拇指 -Os -fno-严格混叠 -O2 -DNDEBUG -G -f异常 -frtti -lstdc++ -I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/include -I$(androidNDKRoot)/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include -D__GLIBC__ -DBOOST_NO_INTRINSIC_WCHAR_T $(androidNDKRoot)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-ar.exe $(androidNDKRoot)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-ranlib.exe linux ;

3。构建提升

bjam.exe --user-config=user-config.jam --without-python --without-mpi 工具集=gcc-android4.4.3 link=static runtime-link=static target-os=linux --stagedir=android > d:\out.txt

4。应用程序.mk

APP_STL := gnustl_static APP_PLATFORM := android-3 APP_CPPFLAGS += -mthumb APP_CPPFLAGS += -Os APP_CPPFLAGS += -fno-strict-aliasing APP_CPPFLAGS += -O2 APP_CPPFLAGS += -DNDEBUG APP_CPPFLAGS += -g APP_CPPFLAGS += -fexceptions APP_CPPFLAGS += -frtti APP_CPPFLAGS += -lstdc++ APP_CPPFLAGS += -D__GLIBC__ APP_CPPFLAGS += -DBOOST_NO_INTRINSIC_WCHAR_T APP_CPPFLAGS += -L/cygdrive/d/Android/boost_1_46_0/android/lib/

5。安卓.mk

# 如何 # http://source.android.com/porting/build_cookbook.html # LOCAL_PATH:= $(调用我的目录) # ================================================== ============== #libudt # ================================================== ============== 包括 $(CLEAR_VARS) LOCAL_MODULE := libudt LOCAL_C_INCLUDES += /cygdrive/d/Android/boost_1_46_0/ LOCAL_SRC_FILES += udt.cpp LOCAL_STATIC_LIBRARIES := boost_thread-gcc-mt-s-1_46 包括 $(BUILD_SHARED_LIBRARY)

6。 udt.cpp

#include “升压/bind.hpp” #include “升压/thread.hpp” 无效 thread_fn (int) { } extern "C" int func1 () { boost::thread thrd (boost::bind (thread_fn, 1)); thrd.join(); 返回0; }

7。 $NDK/ndk-build

编译++拇指:udt > > >': D:/Android/boost_1_46_0/boost/thread/detail/thread.hpp:204: 未定义引用`boost::thread::start_thread()' D:/Android/boost_link/obj/local/armeabi/objs/udt/udt.o:在函数`func1'中: D:/Android/boost_link/jni/udt.cpp:19: 未定义引用`boost::thread::join()' D:/Android/boost_link/jni/udt.cpp:20:未定义对`boost::thread::~thread()'的引用 D:/Android/boost_link/jni/udt.cpp:20:未定义对`boost::thread::~thread()'的引用 D:/Android/boost_link/obj/local/armeabi/objs/udt/udt.o:(.data.rel.ro._ZTIN5boost6detail11thread_dataINS_3_bi6bind_tIvPFv iENS2_5list1INS2_5valueIiEEEEEEEE[typeinfo for boost::detail::thread_data > > >]+0x8): undefined reference to `typeinfo for boost::detail::thread_data_base' collect2: ld 返回 1 个退出状态 制作:*** [/cygdrive/d/Android/boost_link/obj/local/armeabi/libudt.so] 错误 1

【问题讨论】:

    标签: c++ android gcc boost android-ndk-r5


    【解决方案1】:

    我们目前通过在库的 makefile 中简单地包含相关的 boost 文件来使用 boost 的某些部分。

    【讨论】:

      【解决方案2】:

      不知道能不能用gcc,然后把静态库链接到Android平台。 我所知道的是,一切都必须在NDK编译器下编译(因为指令集不同)。

      你可以使用这个: https://github.com/MysticTreeGames/Boost-for-Android (.tar)

      您将需要 NDK 的 customized version

      【讨论】:

      • NDK 编译器是 gcc,上面的日志清楚地表明使用了正确的编译器。不再需要 Crystax NDK;从第 5 版开始,gnu stdlibc++ 是标准 SDK 的一部分。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      相关资源
      最近更新 更多