Search code examples
cios8xcode7-beta2bitcode

iOS library to BitCode


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


Solution

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