I recently downloaded Xcode 7 beta, and Xcode complains about some of my C libraries not being compiled into BitCode. How would I go about telling Clang to produce BitCode t
What you need is -fembed-bitcode. When ENABLE_BITCODE is enabled, Xcode builds with -fembed-bitcode-marker for regular builds and with -fembed-bitcode for archive builds. One option simply "marks" where the bitcode would be in the binary after an archive build and enforces the new bitcode rules, while the other actually does the full-on bitcode generation, which is likely slower and thus not enabled on every kind of build.
Syo Ikeda's guide to handling BITCODE might also help you:
You can find the full slide deck here.
If you're still having trouble after adding the -fembed-bitcode
to the Other C flags, search for "Enable Bitcode" under "Build Options" and set it to No. This will allow you to archive properly.
When building static libraries you must add the following for bitcode generation:
-fembed-bitcode
for a dynamic library you need to additionally link with
-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).Go the Build Settings. Search for "custom compiler flags".
Add -fembed-bitcode
to Other C Flags.
This will ensure that the lib is built with bitcode compatibility at compile time. I made this for iOS 64 bit and 32 bit, and lipo'd them into one.
Works like a charm.
Since you guys had queries, here's a screenshot of the settings: The settings are same for the project target and the SDK target.
The bitcode lib will not work with Xcode 6.
If you are building a Static Library and would like to enable the bitcode, just the (1) ENABLE_BITCODE = YES may not be enough.
(2) Also with the setting -fembed-bitcode
the error below was still being thrown for multiple files when built in Teamcity
bitcode bundle could not be generated because ‘/path/fileInYourStaticLib.a(fileInYourStaticLib.o)’ was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture arm64
Few tips/things to consider that helped me to ultimately solve the issue, in addition to the above steps (1) and (2)
Make Sure you set the variable 'Other C Flags' to "-fembed-bitcode" on the 'PROJECT', and all the 'TARGETS'.
If there are multiple projects that you are trying to create a static library for, make sure all the projects have "-fembed-bitcode"
enabled.
On Build Settings, click on the + sign at the top to add a user-defined build setting with the name
BITCODE_GENERATION_MODE, and set Debug to
marker, Release to
bitcode
If the above steps doesn't work, you can also try this option. On Build Settings -> Other C flags, set Debug to
-fembed-bitcode-marker, and Release to
-fembed-bitcode
This blog was of great help https://medium.com/@heitorburger/static-libraries-frameworks-and-bitcode-6d8f784478a9
Also every time you make the above changes, try deleting the DerivedData, Clean the XCode Project, and possibly quit and restart XCode