如何与android的静态boost库链接?

发布于 2024-10-19 12:11:44 字数 3393 浏览 2 评论 0原文

我在使用 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 ;

using 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
    -mthumb
    -Os
    -fno-strict-aliasing
    -O2
    -DNDEBUG
    -g
    -fexceptions
    -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. 构建 boost

bjam.exe --user-config=user-config.jam --without-python --without-mpi toolset=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. Android.mk

#   Howto
#   http://source.android.com/porting/build_cookbook.html
#

LOCAL_PATH:= $(call my-dir)

# ==============================================================
# libudt
# ==============================================================

include $(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

include $(BUILD_SHARED_LIBRARY)

6. udt.cpp

#include "boost/bind.hpp"
#include "boost/thread.hpp"

void thread_fn (int)
{
}

extern "C" int func1 ()
{
    boost::thread thrd (boost::bind (thread_fn, 1));
    thrd.join ();
    return 0;
}

7. $NDK/ndk-build

Compile++ thumb  : udt  > > >':
D:/Android/boost_1_46_0/boost/thread/detail/thread.hpp:204: undefined reference to `boost::thread::start_thread()'
D:/Android/boost_link/obj/local/armeabi/objs/udt/udt.o: In function `func1':
D:/Android/boost_link/jni/udt.cpp:19: undefined reference to `boost::thread::join()'
D:/Android/boost_link/jni/udt.cpp:20: undefined reference to `boost::thread::~thread()'
D:/Android/boost_link/jni/udt.cpp:20: undefined reference to `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 returned 1 exit status
make: *** [/cygdrive/d/Android/boost_link/obj/local/armeabi/libudt.so] Error 1

I have problem porting and linking the boost libraries to android using Android-ndk-r5b.
I build boost libraries first (without mpi, python) using these steps:

1.commented line 53 in boost_1_46_0\libs\thread\build:

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

2. create the file user-config.jam in boost root directory

androidNDKRoot = ../android-ndk-r5b ;

using 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
    -mthumb
    -Os
    -fno-strict-aliasing
    -O2
    -DNDEBUG
    -g
    -fexceptions
    -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. build boost

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

4. Application.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. Android.mk

#   Howto
#   http://source.android.com/porting/build_cookbook.html
#

LOCAL_PATH:= $(call my-dir)

# ==============================================================
# libudt
# ==============================================================

include $(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

include $(BUILD_SHARED_LIBRARY)

6. udt.cpp

#include "boost/bind.hpp"
#include "boost/thread.hpp"

void thread_fn (int)
{
}

extern "C" int func1 ()
{
    boost::thread thrd (boost::bind (thread_fn, 1));
    thrd.join ();
    return 0;
}

7. $NDK/ndk-build

Compile++ thumb  : udt  > > >':
D:/Android/boost_1_46_0/boost/thread/detail/thread.hpp:204: undefined reference to `boost::thread::start_thread()'
D:/Android/boost_link/obj/local/armeabi/objs/udt/udt.o: In function `func1':
D:/Android/boost_link/jni/udt.cpp:19: undefined reference to `boost::thread::join()'
D:/Android/boost_link/jni/udt.cpp:20: undefined reference to `boost::thread::~thread()'
D:/Android/boost_link/jni/udt.cpp:20: undefined reference to `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 returned 1 exit status
make: *** [/cygdrive/d/Android/boost_link/obj/local/armeabi/libudt.so] Error 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有伤那来痛 2024-10-26 12:11:44

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

We currently use some parts of boost by simply including relevant boost files in the makefile for the library.

我们的影子 2024-10-26 12:11:44

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

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

您将需要一个 NDK 的自定义版本

I don't know if you can use gcc and then link the static libraries into the Android platform.
What I know is that everything must be compiled under the NDK compiler (because the instruction set is different).

You can use this:
https://github.com/MysticTreeGames/Boost-for-Android (.tar)

You will need a customized version of the NDK.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文