欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

在win7系统上使用NDK编译BOOST

程序员文章站 2022-07-14 09:52:42
...

1. 下载最新版BOOST:

    https://dl.bintray.com/boostorg/release/1.70.0/source/

    下载NDK:

    https://developer.android.google.cn/ndk/downloads/revision_history.html

2. 打开一个cmd,进入boost目录,执行bootstrap.bat,生成b2.exe

3. 修改boost_1_70_0目录下的project-config.jam为:

    

androidNDKRoot = D:/Android/android-ndk-r20 ;

using clang : arm64 
:
    $(androidNDKRoot)/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe  
:
    <compileflags>--sysroot=$(androidNDKRoot)/sysroot 
    <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>-I$(androidNDKRoot)/sysroot/usr/include/aarch64-linux-android 
    <compileflags>-g 
    <compileflags>-O3
    <cxxflags>-std=c++14
    <compileflags>--target=aarch64-arm-linux-androideabi 
;

修改androidNDKRoot = D:/Android/android-ndk-r20 ;为你的实际目录即可。注意只能使用/而不能使用\。

4. 将以下目录加入PATH环境变量

 

D:\Android\android-ndk-r20\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\aarch64-linux-android\bin

可以在cmd中临时设置:

set PATH=%PATH%;D:\Android\android-ndk-r20\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\aarch64-linux-android\bin

5. 在boost_1_70_0目录中执行编译命令即可:

   

b2 target-os=android toolset=clang-arm64 link=static

在编译过程中可能会遇到问题:

Performing configuration checks

    - default address-model    : none
    - default architecture     : none

Building the Boost C++ Libraries.


D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/tools\common.jam:977: in toolset-tag
*** argument error
* rule numbers.less ( n1 n2 )
* called with: ( 4 )
* missing argument n2
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/util\numbers.jam:66:see definition of rule 'numbers.less' being called
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/tools\common.jam:854: in common.format-name
D:/Android/android-ndk-r20/sources/boost_1_70_0\boostcpp.jam:197: in boostcpp.tag
Jamroot:198: in Jamfile<D:\Android\android-ndk-r20\sources\boost_1_70_0>.tag
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/kernel\modules.jam:107: in modules.call-in
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/util\indirect.jam:105: in indirect.call
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\virtual-target.jam:476: in _adjust-name
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\virtual-target.jam:274: in abstract-file-target.__init__
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\virtual-target.jam:582: in [email protected]__init__
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/kernel\class.jam:90: in class.new
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:576: in generated-targets
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:474: in construct-result
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:418: in run-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:392: in generator.run
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/tools/generators\archive-generator.jam:32: in archive-generator.run
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/tools\unix.jam:87: in c[email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:1019: in try-one-generator-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:1081: in try-one-generator
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:1319: in construct-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:1405: in generators.construct
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/tools/generators\lib-generator.jam:59: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:1019: in try-one-generator-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:1081: in try-one-generator
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:1319: in construct-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\generators.jam:1405: in generators.construct
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1614: in construct
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1363: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:812: in generate-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:784: in [email protected]-target.generate
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:933: in targets.generate-from-reference
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1276: in generate-dependencies
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1333: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:812: in generate-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:784: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:933: in targets.generate-from-reference
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1276: in generate-dependencies
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1333: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:812: in generate-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:784: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:933: in targets.generate-from-reference
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1276: in generate-dependencies
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1333: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:812: in generate-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:784: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:933: in targets.generate-from-reference
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1276: in generate-dependencies
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1333: in alias-target-class.generate
D:/Android/android-ndk-r20/sources/boost_1_70_0\boostcpp.jam:403: in build-multiple
D:/Android/android-ndk-r20/sources/boost_1_70_0\boostcpp.jam:393: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:812: in generate-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:784: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:933: in targets.generate-from-reference
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1276: in generate-dependencies
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:1333: in alias-target-class.generate
D:/Android/android-ndk-r20/sources/boost_1_70_0\boostcpp.jam:403: in build-multiple
D:/Android/android-ndk-r20/sources/boost_1_70_0\boostcpp.jam:393: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:812: in generate-really
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:784: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src/build\targets.jam:273: in [email protected]
D:/Android/android-ndk-r20/sources/boost_1_70_0/tools/build/src\build-system.jam:797: in load
D:\Android\android-ndk-r20\sources\boost_1_70_0\tools\build\src/kernel\modules.jam:295: in import
D:\Android\android-ndk-r20\sources\boost_1_70_0\tools\build\src/kernel/bootstrap.jam:139: in boost-build
D:\Android\android-ndk-r20\sources\boost_1_70_0\boost-build.jam:17: in module scope

解决办法是:将D:\Android\android-ndk-r20\sources\boost_1_70_0\tools\build\src\tools\common.jam文件中的982行内容注释掉:

   

# Ditto, from Clang 4
#   if ( $(tag) = clang || $(tag) = clangw ) && [ numbers.less 3 $(version[1]) ]
#    {
#        version = $(version[1]) ;
#    }

最终生成的库位置:

D:\Android\android-ndk-r20\sources\boost_1_70_0\stage\lib

 

参考了以下文章:

https://github.com/boostorg/build/issues/385

https://github.com/boostorg/boost/issues/258