Boost platform-wide compilation method and boost platform Compilation Method
0. General rules
Boost comes with a compilation tool bjam, which is cross-platform and compiled by itself. The bootstrap. sh and bootstrap. bat scripts in the boost directory are used to compile * nix and bjam in windows respectively. The bootstrap script can pass in parameters to generate a specific boost compilation configuration during bjam compilation. These configurations are saved in the newly generated project-config.jam, but you can also overwrite them by passing in parameters when running bjam. The b2 generated at the same time is the bjam proxy, and the running effect is similar.
Run in Terminal
bjam --show-libraries
Lists all the libraries to be compiled.
During actual compilation, you can pass in-with-xxx to select which libraries to compile, or pass in-without-xxx to select which libraries not to compile. If not passed, the project-config.jam settings are read, and if not, all libraries are compiled.
More parameters can be used
bjam --help
. For example, if the database is compiled into a static library or a dynamic library, whether the database is static or dynamic during runtime, and whether to install the database after compilation.
Note:
The earlier version of boost may cause compilation problems. Try to use the new version. Bjam supports different parameters in * nix and windows.
1. iOS compiling environment:
OS X Yosemite 10.10.3
Xcode 6.3.1 (6D1002)
Boost 1.57
Steps:
Save the following script as build_boost.sh and run it directly:
#! /Bin/bash # http://blog.csdn.net/hursing/article/details/45439087#, Please modify the path, cd to the directory after boost decompression dir = 'dirname $0 'CD "$ dir /.. /.. /third_party/boost_000057_0 "# exit if [-e. /stage/lib/libboost_date_time.a]; then echo "libraries exist. no need to build. "exit 0fi # the following code references the https://gist.github.com/rsobik/7513324. The boost version used in the original article is older and cannot be used. :$ {COMPILER: = "clang ++" }:: {IPHONE_SDKVERSION: = 'xcodebuild-showsdks | grep iphoneos | egrep "[[: digit:] + \. [[: digit:] + "-o | tail-1 '}:: {XCODE_ROOT: = 'xcode-select-print-path' }:: {EXTRA_CPPFLAGS: = "-DBOOST_AC_USE_PTHREADS-DBOOST_SP_USE_PTHREADS-stdlib = libc ++"} echo "IPHONE_SDKVERSION: $ IPHONE_SDKVERSION" echo "XCODE_ROOT: $ XCODE_ROOT" echo "COMPILER: $ COMPILER "echo" bootstrap "# If this script is called by Xcode It causes failure for some variables of xcode export, so env-I is added. Run this script directly on the command line to remove env-I from env-I bash. /bootstrap. shecho "write project-config.jam" # default survival of project-config.jam is compiled Mac version, here directly replace rm project-config.jamcat> project-config.jam <EOFusing darwin: $ {IPHONE_SDKVERSION }~ Iphone: $ XCODE_ROOT/Toolchains/XcodeDefault. xctoolchain/usr/bin/$ COMPILER-arch armv7-arch arm64-fvisibility = hidden-fvisibility-inlines-hidden $ EXTRA_CPPFLAGS: <striper> <root> $ XCODE_ROOT/Platforms/iPhone. platform/Developer: <architecture> arm <target-OS> iphone; using darwin :$ {IPHONE_SDKVERSION }~ Iphonesim: $ XCODE_ROOT/Toolchains/XcodeDefault. xctoolchain/usr/bin/$ COMPILER-arch x86_64-fvisibility = hidden-fvisibility-inlines-hidden $ EXTRA_CPPFLAGS: <striper> <root> $ XCODE_ROOT/Platforms/iPhoneSimulator. platform/Developer: <architecture> ia64 <target-OS> iphone; EOF # in the above Code, two using darwin settings are used to compile the real machine version and Simulator version respectively. One more CPU architecture requires an arch xxx. For example, in the simulator version, if it is a 32-bit cpu, you can add-arch imo-echo "build boost iphone dev ". /bjam-j16 -- with-date_time -- with-filesystem -- with-system -- with-thread -- build-dir = iphone-build -- stagedir = iphone-build/stage toolset = darwin architecture = arm target-OS = iphone macosx-version = iphone-$ {IPHONE_SDKVERSION} define = _ LITTLE_ENDIAN link = static stageecho "build boost iphone sim ". /bjam-j16 -- with-date_time -- with-filesystem -- With-system -- with-thread -- build-dir = iphonesim-build -- stagedir = iphonesim-build/stage -- toolset = darwin-$ {IPHONE_SDKVERSION }~ Iphonesim architecture = ia64 target-OS = iphone macosx-version = iphonesim-$ {IPHONE_SDKVERSION} link = static stageecho "lipo" # integrate library files under various architectures, so that you can set less search paths in xcode. More thoroughly, each database Shard is merged into a large database. However, unless the static library is added to the code repository, it is a waste of time. For details about the large library to be merged, refer to https://gist.github.com/rsobik/7513324. Mkdir-p stage/liblipo-create iphone-build/stage/lib/libboost_date_time.a iphonesim-build/stage/lib/libboost_date_time.a-output stage/lib/libboost_date_time.alipo-create iphone-build/stage /lib/libboost_filesystem.a iphonesim-build/stage/lib/libboost_filesystem.a-output stage/lib/Alibaba-create iphone-build/stage/lib/libboost_system.a iphonesim-build/stage/lib/libboost_system.a -output stage/lib/libboost_system.alipo-create iphone-build/stage/lib/libboost_thread.a iphonesim-build/stage/lib/libboost_thread.a-output stage/lib/libboost_thread.a # The library file is stored. /stage/lib/echo "Completed successfully"
Integrated into Xcode
I am still familiar with using Xcode. Therefore, you can integrate the above script into xcode. In a project, the Xcode menu File-> New-> Target... -> Other-> Aggregate-> named boost, finish-> select Build Phases in the target attribute-> click the plus sign on the left-> New Run Script Phase-> Fill in bash. /build_boost.sh-> Fill in the library file search path and link each boost library. The main target must also be configured with boost target, so as to avoid Link errors before boost compilation.
2. Android platform Compilation
Android compilation method has two kinds: one is the same as iOS, overwrite the project-config.jam introduce NDK compilation tool settings, and then use bjam to compile; the other is to write Android. mk by yourself. Write your own project-config.jam because you need to take into account a lot of CPU architecture and (whether it is to write jam or the main project of Android. mk are more troublesome), so this article uses the latter.
Environment
Ubuntu 14.04 64bit/Linux Mint 17 64bit
NDK r10c
Boost 1.57
Procedure
The content of Android. mk is as follows:
Include $ (CLEAR_VARS) LOCAL_PATH: = $ (ROOT_PATH)/third_party/boost_000057_0local_module: = boost # the library to be compiled. Add cpp in the libs directory. LOCAL_SRC_FILES + = \ libs/filesystem/src/path. cpp \ libs/filesystem/src/path_traits.cpp \ libs/filesystem/src/operations. cpp \ libs/filesystem/src/codecvt_error_category.cpp \ libs/filesystem/src/portability. cpp \ libs/filesystem/src/libraries \ libs/date_time/src/gregorian/date_generators.cpp \ libs/date_time/src/gregorian/greg_month.cpp \ libs/date_time/src/gregorian/Libraries Pp \ libs/date_time/src/gregorian/gregorian_types.cpp \ libs/date_time/src/posix_time/posix_time_types.cpp \ libs/system/src/error_code.cpp # To integrate boost into the dynamic library, -fPIC is required. Otherwise, a link error occurs. For more information, see GoogleLOCAL_CFLAGS + =-fPIC-frtti-fexceptionsinclude $ (BUILD_STATIC_LIBRARY)
3. Windows compiling environment
64-bit SP1 for Windows 7 flagship Edition
Visual Studio Ultimate 2013
Boost 1.57
Procedure
The following is the content of build_boost.bat, which can be directly executed:
cd ..\..\third_party\boost_1_57_0if not exist .\b2.exe ( call .\bootstrap.bat .\b2.exe -j5 --with-date_time --with-filesystem --with-system --with-thread --with-regex)
Integrated into:
Project Properties-> Configuration Properties-> Build Events-> Pre-Link Event-> Command Line-> enter build_boost.bat
4. Linux compiling environment
Ubuntu 14.04 64bit/Linux Mint 17 64bit
Gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
Boost 1.57/1.58
Procedure
Compile directly. The following are terminal commands
cd boost_1_57_0bash bootstrap.sh./b2
In this way, all the library files can be found under boost_000057_0/stage/lib.
If cmakeis used to organize compilation, part of the content in cmakelists.txt of the main project is as follows:
Include (ExternalProject) ExternalProject_Add (boost SOURCE_DIR ${ROOT_DIR}/third_party/boost_1_57_0 CONFIGURE_COMMAND bash $ {ROOT_DIR}/third_party/boost_1_57_0/bootstrap. sh -- with-libraries = date_time, thread, filesystem, system BUILD_COMMAND ${ROOT_DIR}/third_party/queues/b2-j10 cflags =-fPIC cxxflags =-fPIC BUILD_IN_SOURCE 1 INSTALL_COMMAND "") set (BOOST_LIBRARIES $ {ROOT_DIR}/third_party/users/stage/lib/users $ {ROOT_DIR}/third_party/users/stage/lib/libboost_system.a $ {ROOT_DIR}/third_party/users/party/ stage/lib/libboost_thread.a $ {ROOT_DIR}/third_party/boost_000057_0/stage/lib/libboost_filesystem.a) #... # Set the link and dependency target_link_libraries (your_target $ {BOOST_LIBRARIES}) add_dependencies (your_target boost)
5. Mac OS X compiling environment
OS X Yosemite 10.10.3
Xcode 6.3.1 (6D1002)
Boost 1.57
Procedure
Same as Linux. The process for integrating to Xcode is similar to that for iOS.
Reprinted please indicate the source: http://blog.csdn.net/hursing