Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the -ObjC flag be applied selectively to static libraries?

TL;DR

How can I make the -ObjC linker flag target a specific static library and not all the static libraries I am linking against in order to avoid unused object files being linked in with my app?


Too Long; Did Read

So you are developing a new iOS app and you add in your homegrown "objcutil" static library which contains a variety of useful Objective-C classes (not implemented as categories) to do various things that have been useful in the past. So far, so good, and only those object files that are being referenced in the utility library are being linked with the app.

Then you decide to integrate the Google Maps SDK which wants you to use the -ObjC Other Linker Flags and all of a sudden dependencies in the utility library fail to be resolved, because you haven't configured Xcode to link to those libraries.

OK I can resolve the missing dependencies easily enough, however you now have unused object files and library dependencies that you don't need and you'd like to be a bit tidier than that.

So how do you avoid OCD overload?


Some reference from the ld manpage:

-ObjC Loads all members of static archive libraries that define an Objective C class or a category. This option does not apply to dynamic shared libraries.


  • Xcode Version: 5.1.1
  • OSX Version: 10.9.4
like image 332
trojanfoe Avatar asked Sep 17 '14 11:09

trojanfoe


1 Answers

OK so the answer is to use -force_load instead of -ObjC as -force_load is more focused.

So WRT to the Google Maps SDK, if you followed the instructions and copied the static framework into the app project directory, then the framework will be in the project root directory and you can remove -ObjC from the Other Linker Flags and replace it with

-force_load GoogleMaps.framework/Versions/Current/GoogleMaps:

enter image description here

Nothing else needs changing.

For other libraries you will need to use the full static library path as the argument to -force_load.

like image 200
trojanfoe Avatar answered Oct 07 '22 21:10

trojanfoe