iOS library to BitCode

CIos8Xcode7 Beta2Bitcode

C Problem Overview


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

C Solutions


Solution 1 - C

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.
  • Xcode itself builds with -fembed-bitcode-marker for regular builds (like deploy to simulator)
  • Xcode only builds with -fembed-bitcode for archive builds / production builds (as this is only needed for Apple).

Solution 2 - C

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.

enter image description here


The bitcode lib will not work with Xcode 6.

Solution 3 - C

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.

Solution 4 - C

> 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.

Solution 5 - C

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)

  1. Make Sure you set the variable 'Other C Flags' to "-fembed-bitcode" on the 'PROJECT', and all the 'TARGETS'.

  2. If there are multiple projects that you are trying to create a static library for, make sure all the projects have "-fembed-bitcode" enabled.

  3. 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

  4. 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

Solution 6 - C

Just to add some details for future noobs like me.

I ran into this problem with libVivoxNative.a when building from unity to iOS. I had to disable bitcode in 4 different spots:

screenshot

Originally I guess I had just set it for the target Unity-iPhone, not the project or the tests/UnityFramework. Changing the setting for all 4 did the trick.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionstack_tomView Question on Stackoverflow
Solution 1 - CDanoli3View Answer on Stackoverflow
Solution 2 - CGautam JainView Answer on Stackoverflow
Solution 3 - CIan HanView Answer on Stackoverflow
Solution 4 - CZeeshanView Answer on Stackoverflow
Solution 5 - CNaishtaView Answer on Stackoverflow
Solution 6 - CAdam BView Answer on Stackoverflow