otool -l yourlib.a | grep bitcode
or
otool -l yourlib.a | grep __LLVM
is the way to go.
But in my case (XCode 7, static iOS library) this did not work (see also the comments byxCocoa).
It seems, that otool
does not report the bitcode if code for the iPhone Simulator's architecture is included (x86_64 or arm64).
You can list the lib's architectures with:
lipo -info yourlib.a
Then you can check for bitcode for each architecture separately, e.g:
otool -arch armv7 -l yourlib.a | grep bitcode
otool -arch arm64 -l yourlib.a | grep bitcode
Bitcode is a compile-time feature (not a link-time feature) which means that every .o file should contain an extra section called __bitcode when built with bitcode. You can confirm whether your binary is bitcode-compatible by running otool -l (my .o or .a file)
.
When you build normally, Xcode adds the build flag -fembed-bitcode-marker
to any clang invocation. This seems to be some sort of 'this is where bitcode would go, if bitcode was enabled' thing, and doesn't actually enable bitcode.
When you "Build & Archive", this flag is replaced by -fembed-bitcode
, which really does build a Bitcode-enabled binary.
There seems to be two ways to make xcodebuild
use -fembed-bitcode
:
xcodebuild -target LookbackSDK archive
instead of xcodebuild -target LookbackSDK build
. This has the side-effect of putting binaries in your Xcode Organizer instead of the build/
folder, though you can work around that by using -exportArchive -archivePath ./build
(thanks @JensAyton)OTHER_CFLAGS="-fembed-bitcode"
. Your xcodebuild
invocation would look something like xcodebuild OTHER_CFLAGS="-fembed-bitcode" -target LookbackSDK build
. The latter is what I chose so that I don't have to change my build system, but it will generate warnings for every file, since now both -fembed-bitcode-marker
and -fembed-bitcode
are sent to clang. Luckilly the latter wins, generating a Bitcode-enabled library!
Once you add bitcode support for the static lib, it won't be compatible with Xcode 6. The app won't archive.
I would like to clearly mention the setting for bitcode as @nevyn's answer confused me a little.
Go to Build settings, search for "custom compiler flags". Add -fembed-bitcode
. This will build your lib with bitcode.
For iOS, this should *just work*. When you are producing your library, the compiler and linker will include the bitcode in the Mach-O file. There are only two things that you should know.
1. If you are not using Xcode, please manually add -femit-bitcode command line option.
2. When using Xcode, bitcode is only produced during archive build, not debug or release build.
When building static libraries you must the following for bitcode generation:
-fembed-bitcode
Note: This command is only available with Xcode7+
In regards to the accepted answer of using -fembed-bitcode-marker
You should be aware that a normal build with the -fembed-bitcode-marker option will produce minimal size embedded bitcode sections without any real content. This is done as a way of testing the bitcode-related aspects of your build without slowing down the build process. The actual bitcode content is included when you do an Archive build.
bwilson Apple Staff. https://forums.developer.apple.com/thread/3971#12225
To be more specific:
-fembed-bitcode-marker
simply marks where the bitcode would be in the binary after an archive build.-fembed-bitcode
actually does the full bitcode generation and embedding, so this is what you need to use for building static libraries.-fembed-bitcode-marker
for regular builds (like deploy to simulator)-fembed-bitcode
for archive builds / production builds (as this is only needed for Apple).