如何将 boost 构建为 Android 的共享库
How to build boost as shared libraries for Android
我用 NDK r21b
.
为 Android armeabiv7a
成功编译了 boost 1.70
我用了user-config.jam:
import os ;
local AndroidNDKRoot = [ os.environ ANDROIDNDKROOT ] ;
local AndroidBinariesPath = [ os.environ CLANGPATH ] ;
local TargetPlatform = [ os.environ TARGET ] ;
using clang : armeabiv7a
:
$(AndroidBinariesPath)/clang++
:
<archiver>$(AndroidBinariesPath)/llvm-ar
<ranlib>$(AndroidBinariesPath)/llvm-ranlib
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-fstack-protector-strong
<compileflags>-Wno-invalid-command-line-argument
<compileflags>-Wno-unused-command-line-argument
<compileflags>-no-canonical-prefixes
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/llvm-libc++/include
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/llvm-libc++abi/include
<compileflags>-I$(AndroidNDKRoot)/sources/android/support/include
<compileflags>-DANDROID
<compileflags>-Wa,--noexecstack
<compileflags>-Wformat
<compileflags>-Werror=format-security
<compileflags>-DNDEBUG
<compileflags>-O2
<compileflags>$(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(PlatformOS)-x86_64
<compileflags>-target
<compileflags>armv7a-linux-androideabi21
<compileflags>-march=armv7-a
<compileflags>-mfloat-abi=softfp
<compileflags>-mfpu=vfpv3-d16
<compileflags>-mthumb
<compileflags>-fPIC
<compileflags>-fno-integrated-as
<compileflags>--sysroot
<compileflags>$(AndroidNDKRoot)/sysroot
<compileflags>-isystem
<compileflags>$(AndroidNDKRoot)/sysroot/usr/include/arm-linux-androideabi
<compileflags>-D__ANDROID_API__=21
;
和命令行:
set ANDROIDNDKROOT=C:\Android\android_sdk\ndk-bundle
set NDKVER=r21b
set CLANGPATH=%ANDROIDNDKROOT%\toolchains\llvm\prebuilt\windows-x86_64\bin
set PATH=%PATH%;%CLANGPATH%
bjam -q link=static --without-math --without-context --without-coroutine --without-fiber --without-python --build-type=minimal architecture=arm --ignore-site-config -j8 target-os=android toolset=clang-armeabiv7a threading=multi --layout=tagged --build-dir=build_static_armeabiv7a/%NDKVER% --stagedir=stage_static_armeabiv7a_%NDKVER% stage
这非常有效。
现在,我想构建共享库,所以我 运行:
bjam -q link=shared --without-math --without-context --without-coroutine --without-fiber --without-python --build-type=minimal architecture=arm --ignore-site-config -j8 target-os=android toolset=clang-armeabiv7a threading=multi --layout=tagged --build-dir=build_shared_armeabiv7a/%NDKVER% --stagedir=stage_shared_armeabiv7a_%NDKVER% stage
但是我得到以下错误:
clang-linux.link.dll build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0
clang++: error: unable to execute command: program not executable
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
"C:\Android\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin/clang++" -o "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0" -Wl,-soname -Wl,libboost_atomic-mt-a32.so.1.70.0 -shared -Wl,--start-group "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\lockpool.o" -Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group -fPIC -fvisibility=hidden -fvisibility-inlines-hidden
...failed clang-linux.link.dll build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0...
我尝试使用 -v 手动执行失败的命令以获取更多详细信息:
"C:\Android\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin/clang++" -o "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0" -Wl,-soname -Wl,libboost_atomic-mt-a32.so.1.70.0 -shared -Wl,--start-group "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\lockpool.o" -Wl,-Bdynamic -Wl,--end-group -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -v
然后报告的错误是:
"ld" -m i386pep --shared -Bdynamic -e DllMainCRTStartup --enable-auto-image-base -o "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0" dllcrt2.o crtbegin.o "-LC:\Android\r21a_Qt5_14\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\x86_64-w64-mingw32\lib" "-LC:\Android\r21a_Qt5_14\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib" "-LC:\Android\r21a_Qt5_14\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\x86_64-w64-mingw32/sys-root/mingw/lib" -soname libboost_atomic-mt-a32.so.1.70.0 --start-group "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\lockpool.o" -Bdynamic --end-group -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt crtend.o
clang++: error: unable to execute command: program not executable
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
似乎没有找到“ld”,我想我应该告诉构建系统什么时候有“ld”,但是我在 C:\Android\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin
中找不到,也找不到如何在中指定“ld”路径user-config.jam
.
如有任何帮助,我们将不胜感激!
通过查看“ld.exe”在 C:\Android\android_sdk\ndk-bundle\toolchains\llvm
文件夹中的位置,我在 C:\Android\r21a_Qt5_14\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\<some platform name>\bin
下找到了一些,因此我得出结论,目标平台可能丢失了。
我补充道:
<linkflags>-target
<linkflags>armv7a-linux-androideabi21
在 user-config.jam
中,我可以将 boost 编译为共享库。
我用 NDK r21b
.
armeabiv7a
成功编译了 boost 1.70
我用了user-config.jam:
import os ;
local AndroidNDKRoot = [ os.environ ANDROIDNDKROOT ] ;
local AndroidBinariesPath = [ os.environ CLANGPATH ] ;
local TargetPlatform = [ os.environ TARGET ] ;
using clang : armeabiv7a
:
$(AndroidBinariesPath)/clang++
:
<archiver>$(AndroidBinariesPath)/llvm-ar
<ranlib>$(AndroidBinariesPath)/llvm-ranlib
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-fstack-protector-strong
<compileflags>-Wno-invalid-command-line-argument
<compileflags>-Wno-unused-command-line-argument
<compileflags>-no-canonical-prefixes
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/llvm-libc++/include
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/llvm-libc++abi/include
<compileflags>-I$(AndroidNDKRoot)/sources/android/support/include
<compileflags>-DANDROID
<compileflags>-Wa,--noexecstack
<compileflags>-Wformat
<compileflags>-Werror=format-security
<compileflags>-DNDEBUG
<compileflags>-O2
<compileflags>$(AndroidNDKRoot)/toolchains/arm-linux-androideabi-4.9/prebuilt/$(PlatformOS)-x86_64
<compileflags>-target
<compileflags>armv7a-linux-androideabi21
<compileflags>-march=armv7-a
<compileflags>-mfloat-abi=softfp
<compileflags>-mfpu=vfpv3-d16
<compileflags>-mthumb
<compileflags>-fPIC
<compileflags>-fno-integrated-as
<compileflags>--sysroot
<compileflags>$(AndroidNDKRoot)/sysroot
<compileflags>-isystem
<compileflags>$(AndroidNDKRoot)/sysroot/usr/include/arm-linux-androideabi
<compileflags>-D__ANDROID_API__=21
;
和命令行:
set ANDROIDNDKROOT=C:\Android\android_sdk\ndk-bundle
set NDKVER=r21b
set CLANGPATH=%ANDROIDNDKROOT%\toolchains\llvm\prebuilt\windows-x86_64\bin
set PATH=%PATH%;%CLANGPATH%
bjam -q link=static --without-math --without-context --without-coroutine --without-fiber --without-python --build-type=minimal architecture=arm --ignore-site-config -j8 target-os=android toolset=clang-armeabiv7a threading=multi --layout=tagged --build-dir=build_static_armeabiv7a/%NDKVER% --stagedir=stage_static_armeabiv7a_%NDKVER% stage
这非常有效。
现在,我想构建共享库,所以我 运行:
bjam -q link=shared --without-math --without-context --without-coroutine --without-fiber --without-python --build-type=minimal architecture=arm --ignore-site-config -j8 target-os=android toolset=clang-armeabiv7a threading=multi --layout=tagged --build-dir=build_shared_armeabiv7a/%NDKVER% --stagedir=stage_shared_armeabiv7a_%NDKVER% stage
但是我得到以下错误:
clang-linux.link.dll build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0
clang++: error: unable to execute command: program not executable
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
"C:\Android\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin/clang++" -o "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0" -Wl,-soname -Wl,libboost_atomic-mt-a32.so.1.70.0 -shared -Wl,--start-group "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\lockpool.o" -Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group -fPIC -fvisibility=hidden -fvisibility-inlines-hidden
...failed clang-linux.link.dll build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0...
我尝试使用 -v 手动执行失败的命令以获取更多详细信息:
"C:\Android\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin/clang++" -o "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0" -Wl,-soname -Wl,libboost_atomic-mt-a32.so.1.70.0 -shared -Wl,--start-group "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\lockpool.o" -Wl,-Bdynamic -Wl,--end-group -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -v
然后报告的错误是:
"ld" -m i386pep --shared -Bdynamic -e DllMainCRTStartup --enable-auto-image-base -o "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\libboost_atomic-mt-a32.so.1.70.0" dllcrt2.o crtbegin.o "-LC:\Android\r21a_Qt5_14\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\x86_64-w64-mingw32\lib" "-LC:\Android\r21a_Qt5_14\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\lib" "-LC:\Android\r21a_Qt5_14\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\x86_64-w64-mingw32/sys-root/mingw/lib" -soname libboost_atomic-mt-a32.so.1.70.0 --start-group "build_shared_armeabiv7a\r21b\boost\bin.v2\libs\atomic\build\clang-linux-armeabiv7a\release\target-os-android\threading-multi\visibility-hidden\lockpool.o" -Bdynamic --end-group -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt crtend.o
clang++: error: unable to execute command: program not executable
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
似乎没有找到“ld”,我想我应该告诉构建系统什么时候有“ld”,但是我在 C:\Android\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin
中找不到,也找不到如何在中指定“ld”路径user-config.jam
.
如有任何帮助,我们将不胜感激!
通过查看“ld.exe”在 C:\Android\android_sdk\ndk-bundle\toolchains\llvm
文件夹中的位置,我在 C:\Android\r21a_Qt5_14\android_sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\<some platform name>\bin
下找到了一些,因此我得出结论,目标平台可能丢失了。
我补充道:
<linkflags>-target
<linkflags>armv7a-linux-androideabi21
在 user-config.jam
中,我可以将 boost 编译为共享库。