How to Build Boost-Libraries for Iphone

How to build Boost-Libraries for iPhone

Start a new project in Xcode using the iPhone Static Library project template.
Then import the source and headers, and compile it that way. The result should be an iPhone compatible static library

C++ Boost on iPhone

This blog will probably help you.

It says that Pete Goodliffe wrote a script that builds the boost libraries into an iOS framework. There is also an XCode project compiling the whole thing.

If people tell you that you can't use custom frameworks in iOS applications this is not true. So long as the framework is properly built (architectures for i386,armv6 and armv7 all lipoed together) this will work.

I haven't tried that particular framework but if it's correctly setup I am sure this will do the trick.

Keep us posted.

Building Boost for iOS in a CMake Superbuild - Post-Build Processing Dependency

Basically, Boost will always inject -arch arm no matter what you'd prefer. In the end I switched to using a shell script to build Boost and clean it up. Given that Boost has its own build system, this is probably as good as it gets.

The following code uses cmake to download and kick off the Boost compilation script.

boost.cmake

include( ExternalProject )

set_property( DIRECTORY PROPERTY EP_BASE third_party )

set( BOOST_URL "http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.bz2" )
set( BOOST_SHA1 "9f1dd4fa364a3e3156a77dc17aa562ef06404ff6" )
set( BOOST_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/boost )
set( BOOST_INCLUDE_DIR ${BOOST_INSTALL}/include )
set( BOOST_LIB_DIR ${BOOST_INSTALL}/lib )

list( APPEND DEPENDENCIES external_boost )
set( DEPENDENCIES "${DEPENDENCIES}" PARENT_SCOPE )
ExternalProject_Add( external_boost
PREFIX boost
URL ${BOOST_URL}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cmake/lipo-library.sh <SOURCE_DIR>
BUILD_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cmake/boost-compile.sh <SOURCE_DIR> <INSTALL_DIR>
INSTALL_COMMAND ""
INSTALL_DIR ${BOOST_INSTALL} )

list( APPEND EXTRA_CMAKE_ARGS
-DBOOST_ROOT=${BOOST_INSTALL}
-DBoost_NO_SYSTEM_PATHS=ON )
set( EXTRA_CMAKE_ARGS "${EXTRA_CMAKE_ARGS}" PARENT_SCOPE )

boost-compile.sh

#!/bin/bash

SOURCE_DIR="$1"
INSTALL_DIR="$2"

BOOST_MODULES=( "date_time" "system" "filesystem" )
VERBOSE_LOGGING=false
FORCE_REBUILD=true
NCPU=8

MIN_IOS_VERSION="8.0"
ENABLE_BITCODE=true

ARCHITECTURE_FAMILIES=( "arm" "x86" )
X86_COMPILE_ARCHITECTURES=( "i386" "x86_64" )
ARM_COMPILE_ARCHITECTURES=( "armv7" "armv7s" "arm64" )
ALL_ARCHITECTURES=( "${X86_COMPILE_ARCHITECTURES[@]}" "${ARM_COMPILE_ARCHITECTURES[@]}" )

echo "Building Boost libraries ${BOOST_MODULES[*]}"
RESULTS_DIRECTORIES=()
for ARCHITECTURE_FAMILY in "${ARCHITECTURE_FAMILIES[@]}"; do
SDK=""
TARGET_OS="iphone"
if [[ "${ARCHITECTURE_FAMILY}" == "arm" ]]; then
SDK="iphoneos"
SDK_SHORT="iphone"
elif [[ "${ARCHITECTURE_FAMILY}" == "x86" ]]; then
SDK="iphonesimulator"
SDK_SHORT="iphonesim"
fi

XCODE_PLATFORM_PATH="$(xcrun --sdk ${SDK} --show-sdk-platform-path )"
XCODE_IOS_CLANG_PATH="$( xcrun --sdk ${SDK} -f clang++ )"
XCODE_SDK_VERSION="$( xcrun --sdk ${SDK} --show-sdk-version )"

PLATFORM_NAME="darwin"
TOOLSET_PREFIX="${PLATFORM_NAME}"
TOOLSET_SUFFIX="${XCODE_SDK_VERSION}~${SDK_SHORT}"
TOOLSET="${TOOLSET_PREFIX}-${TOOLSET_SUFFIX}"
MACOSX_VERSION="${SDK_SHORT}-${XCODE_SDK_VERSION}"

if [[ "${ARCHITECTURE_FAMILY}" == "arm" ]]; then
SDK_LONG="iPhoneOS${XCODE_SDK_VERSION}.sdk"
# TOOLSET="${TOOLSET_PREFIX}"
elif [[ "${ARCHITECTURE_FAMILY}" == "x86" ]]; then
SDK_LONG="iPhoneSimulator${XCODE_SDK_VERSION}.sdk"
fi
echo "Using toolset ${TOOLSET}"

RESULTS_DIRECTORY="${INSTALL_DIR}/${SDK_LONG}-${ARCHITECTURE_FAMILY}"
mkdir -p "${RESULTS_DIRECTORY}"

CXXFLAGS=()
if [[ "${ARCHITECTURE_FAMILY}" == "arm" ]]; then
for ARM_COMPILE_ARCHITECTURE in "${ARM_COMPILE_ARCHITECTURES[@]}"; do
CXXFLAGS+=( "-arch ${ARM_COMPILE_ARCHITECTURE}" )
done
fi

USER_CONFIG_JAM=()
USER_CONFIG_JAM+=( "using ${TOOLSET_PREFIX} : ${TOOLSET_SUFFIX} :" )
USER_CONFIG_JAM+=( "${XCODE_IOS_CLANG_PATH} :" )
USER_CONFIG_JAM+=( "<striper>" )
USER_CONFIG_JAM+=( "<root>${XCODE_PLATFORM_PATH}/Developer" )
USER_CONFIG_JAM+=( "<compileflags>-std=c++11" )
USER_CONFIG_JAM+=( "<compileflags>-stdlib=libc++" )
USER_CONFIG_JAM+=( "<compileflags>-fvisibility-inlines-hidden" )
USER_CONFIG_JAM+=( "<compileflags>-mios-version-min=${MIN_IOS_VERSION}" )
if [[ "${ENABLE_BITCODE}" ]]; then
USER_CONFIG_JAM+=( "<compileflags>-fembed-bitcode" )
fi
USER_CONFIG_JAM+=( ": <architecture>${ARCHITECTURE_FAMILY} <target-os>${TARGET_OS}" )
USER_CONFIG_JAM+=( ";" )

USER_CONFIG_STRING=$( IFS=$'\n'; echo "${USER_CONFIG_JAM[*]}" )
echo "Creating ${SOURCE_DIR}/tools/build/src/user-config.jam"
echo "${USER_CONFIG_STRING}" > "${SOURCE_DIR}/tools/build/src/user-config.jam"

WITH_LIBRARIES=$( IFS=$','; echo "${BOOST_MODULES[*]}" )

echo "Boostrap Boost"
BOOTSTRAP_OPTIONS=()
BOOTSTRAP_OPTIONS+=( "--with-libraries=${WITH_LIBRARIES}" )
BOOTSTRAP_OPTIONS+=( "--prefix=${RESULTS_DIRECTORY}" )

./bootstrap.sh "${BOOTSTRAP_OPTIONS[@]}"
./b2 --clean-all

echo "B2 Boost"
B2_OPTIONS=()
if [[ "${VERBOSE_LOGGING}" ]]; then
B2_OPTIONS+=( "-d+2" )
fi
if [[ "${FORCE_REBUILD}" ]]; then
B2_OPTIONS+=( "-a" )
fi
B2_OPTIONS+=( "-j${NCPU}" )
B2_OPTIONS+=( "--reconfigure" )
B2_OPTIONS+=( "architecture=${ARCHITECTURE_FAMILY}" )
B2_OPTIONS+=( "address-model=32_64" )
B2_OPTIONS+=( "toolset=${TOOLSET}" )
B2_OPTIONS+=( "target-os=${TARGET_OS}" )
if [[ "${#CXXFLAGS[@]}" -gt 0 ]]; then
B2_OPTIONS+=( "cxxflags=${CXXFLAGS[*]}" )
fi
B2_OPTIONS+=( "macosx-version=${MACOSX_VERSION}" )

if [[ "${ARCHITECTURE_FAMILY}" == "arm" ]]; then
B2_OPTIONS+=( "define=_LITTLE_ENDIAN" )
fi

B2_OPTIONS+=( "link=static" )
B2_OPTIONS+=( "threading=single" )
B2_OPTIONS+=( "variant=release" )
B2_OPTIONS+=( "install" )

echo "./b2 ${B2_OPTIONS[*]}"
./b2 "${B2_OPTIONS[@]}"

RESULTS_DIRECTORIES+=( "${RESULTS_DIRECTORY}" )
done

echo "Create FAT Boost libraries"
FAT_INSTALL_INCLUDE_DIR="${INSTALL_DIR}/include"
FAT_INSTALL_LIBARY_DIR="${INSTALL_DIR}/lib"
mkdir -p "${FAT_INSTALL_INCLUDE_DIR}" "${FAT_INSTALL_LIBARY_DIR}"

BOOST_LIBRARIES=()
for BOOST_MODULE in "${BOOST_MODULES[@]}"; do
BOOST_LIBRARIES+=( "libboost_${BOOST_MODULE}.a" )
done

FAT_LIBBOOST_MODULE_INSTALL_PATHS=()
for BOOST_LIBRARY in "${BOOST_LIBRARIES[@]}"; do
FAT_LIBBOOST_MODULE_INSTALL_PATH="${FAT_INSTALL_LIBARY_DIR}/${BOOST_LIBRARY}"
rm -rf "${FAT_LIBBOOST_MODULE_INSTALL_PATH}"
FAT_LIBBOOST_MODULE_INSTALL_PATHS=( "${FAT_LIBBOOST_MODULE_INSTALL_PATH}" )

INCLUDES_DIRS=()
INTERMEDIATES=()
for RESULTS_DIRECTORY in "${RESULTS_DIRECTORIES[@]}"; do
INCLUDES_DIRS+=( "${RESULTS_DIRECTORY}/include/" )
INTERMEDIATES+=( "${RESULTS_DIRECTORY}/lib/${BOOST_LIBRARY}" )
done

for INCLUDES_DIR in "${INCLUDES_DIRS[@]}"; do
cp -R "${INCLUDES_DIR}" "${FAT_INSTALL_INCLUDE_DIR}"
done

if [[ "${#INTERMEDIATES[@]}" -gt 0 ]]; then
lipo -output "${FAT_LIBBOOST_MODULE_INSTALL_PATH}" -create "${INTERMEDIATES[@]}"
fi
done

echo "Cleaning up Boost build intermediates ${RESULTS_DIRECTORIES[*]}"

rm -rf "${RESULTS_DIRECTORIES[@]}"

echo "Validate Boost libraries contain desired architectures ${ALL_ARCHITECTURES[*]}"
SUCCESS=1
for FAT_LIBBOOST_MODULE_INSTALL_PATH in "${FAT_LIBBOOST_MODULE_INSTALL_PATHS[@]}"; do
"${SOURCE_DIR}/lipo-library.sh" "${FAT_LIBBOOST_MODULE_INSTALL_PATH}" "${ALL_ARCHITECTURES[@]}"
SUCCESS=$?
if [[ ${SUCCESS} -ne 0 ]]; then
break
fi
done

exit "${SUCCESS}"

lipo-library.sh

#!/bin/bash

contains() {
local match="$1"
shift
local list=( "${@}" )

for item in "${list[@]}"; do
if [[ "${item}" == "${match}" ]]; then
echo true
return 1
fi
done

echo false
return 0
}

library="$1"
shift
valid_architectures=( "${@}" )

if [ -z "${library}" ] || [ ! "${#valid_architectures[@]}" -gt 0 ]; then
echo "Usage: $0 <library> <architecture ...>"
exit 1
fi

echo "Library to check ${library}"
echo "Required architectures ${valid_architectures[*]}"

# Check static library for the included architectures and toss anything that shouldn't be included
declare -a archive_library_architectures=()
# Handle finding the architectures in a static library, fat or not.
read -r -a archive_library_architectures <<< "$( lipo -detailed_info "${library}" |
grep architecture |
sed -e 's/.*architecture:\{0,1\} \{0,1\}//' |
tr '\r\n' ' ' |
xargs echo -n )"
echo "${library} contains ${archive_library_architectures[*]}"

missing_architectures=()
for valid_architecture in "${valid_architectures[@]}"; do
has_architecture=$( contains "${valid_architecture}" "${archive_library_architectures[@]}" )
if [[ "${has_architecture}" = false ]]; then
missing_architectures+=( "${valid_architecture}" )
fi
done

if [ "${#missing_architectures[@]}" -gt 0 ]; then
echo "${library} missing ${missing_architectures[*]}"
fi

invalid_architectures=()
for archive_library_architecture in "${archive_library_architectures[@]}"; do
has_architecture=$( contains "${archive_library_architecture}" "${valid_architectures[@]}" )
if [[ "${has_architecture}" = false ]]; then
invalid_architectures+=( "${archive_library_architecture}" )
fi
done

if [ "${#invalid_architectures[@]}" -gt 0 ]; then
echo "${library} invalid ${invalid_architectures[*]}"
fi

for invalid_architecture in "${invalid_architectures[@]}"; do
echo "lipo -remove ${invalid_architecture} -output ${library} $library"
lipo -remove "${invalid_architecture}" -output "${library}" "$library"
done

lipo "${library}" -verify_arch "${valid_architectures[@]}"
result=$?
if [ "${result}" = 0 ]; then
echo "Successfully built ${library} with desired architectures"
else
echo "Failed to build ${library} with desired architectures"
fi

exit "${result}"

How do I add the boost library to Xcode 11? C++

I prefer to keep dependent libraries inside project area. So here is how I just do it for test:

  1. Create new TestBoost project in Xcode from macOS Command-line App C++ template

    (now there is TestBoost folder where TestBoost.xcodeproj is located)

  2. Download latest boost boost_1_72_0.tar.gz and unarchive it

    (now there boost_1_72_0 folder with boost)

  3. Copy boost_1_72_0 folder inside project TestBoost folder, so it is located aside of TestBoost.xcodeproj

  4. In Xcode Project Navigator select TestBoost project > select TestBoost target > select Build Settings tab

  5. In Search Paths section select Header Search Path, double click on value area and enter ${SRCROOT}/boost_1_72_0 (leave non-recursive flag)

  6. Delete default main.cpp from TestBoost target (to avoid main function confusing) and add some example from boost for testing, eg. boost_1_72_0/libs/algorithm/example/search_example.cpp

  7. Build & Run > Success

Output:
Xcode 11 boost integration

How can I compile Boost 1.54.0 (1.54) for the iOS simulator (6.1) on OS X 10.8.4?

I got it building with the boost.sh given here by changing the line in buildBoostForiPhoneOS()

./bjam -j16 --build-dir=iphonesim-build --stagedir=iphonesim-build/stage --toolset=darwin architecture=x86 target-os=iphone macosx-version=iphonesim-${IPHONE_SDKVERSION} link=static stage

to

./bjam -j16 --build-dir=iphonesim-build --stagedir=iphonesim-build/stage --toolset=darwin-${IPHONE_SDKVERSION}~iphonesim architecture=x86 target-os=iphone macosx-version=iphonesim-${IPHONE_SDKVERSION} link=static stage

Modified boost.sh with Boost pkg download and unpacking. Just need to run and all done!

Boost 1.54
MacOSx 10.8.4
Xcode 4.6.3

Official Boost library Support for Android and iOS?

Got reply from boost community
Yes. These platforms are not officially supported because no one has
volunteered to run regression tests regularly for them.

It is not possible for a Boost developer to test on all platforms. So
developers depend on the test results of regression tests run by
volunteers. For example, see
http://beta.boost.org/development/tests/trunk/developer/summary.html

If no one volunteers to run the tests for a particular platform, that
platform is not officially supported.

So if you care about Android or iOS becoming officially supported,
start running regular (preferably daily) regression tests for Boost.
See http://beta.boost.org/development/running_regression_tests.html



Related Topics



Leave a reply



Submit