开发者

How to build Boost-Libraries for iPhone

Can someone tell me, where to find a detailed guide, how to build the Boost-Libraries for using it on th开发者_JAVA技巧e iPhone-Device.

I've allready build the libs for Mac and can use them in my project (only on iPhone-Simulator). While building the project for iPhone-Device, XCode haunts me a warning: "file is not of required architecture" ond some other errors.

Please Help


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


I started here: http://lists.boost.org/boost-build/2009/02/21326.php

With most of Boost you probably don't need to actually compile it, just include the useful headers. In my case, I just did the compiler define in my own Xcode project.


Hey I have updated Pete Goodliffes script in my openFrameworks addon:

  • It currently has arm64, armv7, i386, x86_64
  • Boost 1.59.0 or previous
  • libc++ / std=c++11 -- Now optional release for libstdc++
  • Precompiled and Script to build yourself (so if you need libstdc++ quite easy to change)
    • Supports Xcode 7

[https://github.com/danoli3/ofxiOSBoost][1]


For boost libraries which have only headers files (.hpp) you can just set header search path from your project to them.

For boost libraries with sources you can build static libraries for both ios phone/simulator with next simple steps:

  1. Download and unpack a boost release archive (from https://www.boost.org/users/download/) e.g.: https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.bz2

  2. Run bootstrap.sh with needed libraries to build for instance 'context' (format =library1,library2,...):

./bootstrap.sh --with-libraries=context
  1. Add toolsets with correct paths to installed SDKs to project-config.jam:
# IOS ARM64
using clang : iphoneos
: xcrun clang -arch arm64 -stdlib=libc++ -std=c++11 -miphoneos-version-min=12.0 -fvisibility-inlines-hidden -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
;

# IOS x86_64
using clang : iphonesimulator
: xcrun clang -arch x86_64 -stdlib=libc++ -std=c++11 -miphoneos-version-min=12.0 -fvisibility-inlines-hidden -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
;
  1. Create and run build.sh script (where lib name is libboost_<name>.a):
lib=libboost_context.a
dir='stage/lib'

# Build arm64
./b2 -a -j4 toolset=clang-iphoneos binary-format=mach-o abi=aapcs link=static stage
mv $dir/$lib $dir/arm64_$lib

# Build x86_64
./b2 -a -j4 toolset=clang-iphonesimulator binary-format=mach-o abi=sysv link=static stage
mv $dir/$lib $dir/x86_64_$lib

# Make fat
lipo -create $dir/arm64_$lib $dir/x86_64_$lib -output $dir/$lib

Now you have next compiled static libraries in "/stage/lib" dir for boost context: arm64_libboost_context.a, x86_64_libboost_context.a and fat one libboost_context.a.


We use boost too. To simplify its inclusion into new applications I have created a Xcode project you can drop into your workspace to include boost. It is based on a Makefile so you need the Xcode commandline tools installed.

The project is here https://github.com/Cogosense/iOSBoostFramework.

Clone the project into your workspace, then click on Menu File->"Add Files to workspace". Select iOSBoostFramework/iOSBoostFramework.xcodeproj in the file finder and click add.

The Makefile in the iOSBoostFramework directory controls what is built and how it is built. There is support for Xcode workspace dependencies, bitcode generation, and only the target architectures selected by Xcode are built.

The following libraries are built test, thread, atomic, signals, filesystem, regex, program_options, system date_time, serialization, exception, locale, and random.

All the separate libraries and architectures are combined, the final build output is a FAT boost.framework Framework bundle which can be linked into the application.

The version of boost is specified in the Makefile (currently 1.64.0), it is downloaded, built for all active architectures and installed in the BUILT_PRODUCTS_DIR specified by xcode.


The previous answer helped me when I wanted to build boost for the arm simulator. When you have a Mac with M1 processor and want to use the simulator, you cannot use the arm64 build for the iPhone.

I added this to the project-config.jam:

# IOS Arm Simulator
using clang : iphonesimulatorarm64
: xcrun clang -arch arm64 -stdlib=libc++ -std=c++11 -miphoneos-version-min=10.0 -fvisibility-inlines-hidden -target arm64-apple-ios10.0-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk  ;

Then pass toolset=clang-iphonesimulatorarm64 to the b2 command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜