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 that is compatible with iOS? I've seen similar answers on stackoverflow, but I don't know if they apply to producing BitCode libraries for iOS.
Edit:
I am using the correct setting, -fembed-bitcode, but when I try to archive, I get the error: ld: warning: ignoring file XXXX/XXXX, file was built for archive which is not the architecture being linked (arm64). When I use -fembed-bitcode-marker, I can archive, but I get the error: full bitcode bundle could not be generated because XX/XX was built only with bitcode marker. The library must be generated from Xcode archive build with bitcode enabled.
Any ideas on what is going wrong? The library is compiling successfully, but it doesn't let me archive. I created a simple add function and made it into a library, and I get the same symptoms, so it is not the library I'm compiling.
Edit 2: You must build both the arm64 and armv7 versions using bitcode and lipo them together. Using bitcode doesn't take away the need for a fat library when archiving. source : Link
For iOS apps, bitcode is the default, but optional. If you provide bitcode, all apps and frameworks in the app bundle need to include bitcode. For watchOS apps, bitcode is required.
Bitcode is an Apple technology that enables you to recompile your app to reduce its size. The recompilation happens when you upload your app to App Store Connect or export it for Ad Hoc, Development, or Enterprise distribution. To learn more about bitcode, see Distribution Options.
The embedded bitcode enables Apple to recompile existing applications and make them compatible with the chipsets of new devices.
If you turn BitCode on, then the intermediate representation of the compiled program gets uploaded and Apple will able to recompile and/or optimize your apps for future architectures (as described here). Turning it off is very safe for the time being.
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'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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With