Why is -force_load no longer required for my three-dependent dependencies in Xcode 4.2?

I have a project dependent on a third-party static library and three20 libraries. In Xcode 3.X, to compile my project, I had to use the -force_load flag in the "Other flag builders" build setting and specify each of the three libraries that I wanted to include.

When I tried to create an archive in Xcode 4.2, I got a "duplicate character" error. I solved this by removing seven separate -force_load flags that apply to each of the three libraries I had a dependency on.

My project is now working successfully.

I wonder if anyone can explain to me why this worked. Was there a bug fixed by Xcode 4.2 or a behavior change? This post suggests there was a bug in Xcode 3.2, but it would be great if someone could shed extra light on this topic for me, so I can be sure that I don’t have, maybe they did something wrong by deleting these flags are force_load.

Thanks!

+7
source share
1 answer

When creating a static library (as required by iOS), one of the problems you will encounter is including characters from categories in this library so that they can be used by the application. The -ObjC linker -ObjC should contain enough information to include categories in these built-in frameworks, as Dave Dribin describes in his article here .

However, between iPhone OS 2.0 and 3.0, this stopped working correctly. As I mentioned in this answer , we ran into this problem in the Core Plot framework and found that we needed to add the linker flag -all_load to make the working environment correct. Apple itself posted the QA A QA1490 , which mentions this issue:

For applications with 64-bit and iPhone-OS, a linker error exists that prevents -ObjC from loading object files from static libraries that contain only categories and classes. The workaround is to use -all_load or -force_load.

-all_load forces the linker to load all object files from each archive being viewed, even without Objective-C code. -force_load is available in Xcode 3.2 and later. This allows you to control smaller grains loading the archive. Each -force_load option should be followed by the path to the archive and each object file in this archive will be downloaded.

Unfortunately, a side effect of this is that duplicate characters linked from several libraries can cause errors similar to the ones you experienced.

I published a bug report (back in 2009), and it seems that the latest version of LLVM, which is now used in Xcode, no longer suffers from this linker error. I tried using -ObjC with the goal of the Core Plot iOS static library, and now it works fine. This is welcome news.

+19
source

All Articles