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

TL DR

How can I set the -ObjC linker flag for a specific static library, and not for all the static libraries that I link with to avoid using unused object files in my application?


Too long; Read

So, you are developing a new application for iOS and adding to your old home library “objcutil”, which contains many useful Objective-C classes (not implemented as categories) to do various things that were useful in the past. So far, so good, and only those object files that are referenced in the utility library are associated with the application.

Then you decide to integrate the Google Maps SDK in which you want to use the -ObjC Other Linker Flags and all unexpected dependencies in the utility library cannot be resolved since you did not configure Xcode to communicate with these libraries.

OK. I can easily resolve missing dependencies, but now you have unused library object and library files that you don’t need, and you would like to be a little more neat.

So how do you avoid OCD overload?


Some links from ld manpage:

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


  • Xcode Version: 5.1.1
  • OS Version: 10.9.4
+6
source share
1 answer

OK, so the answer should use -force_load instead of -ObjC , since -force_load more focused.

So, WRT in the Google Maps SDK, if you followed the instructions and copied the static structure into the application project directory, the structure will be in the project root directory, and you can remove -ObjC from other linker flags and replace it with

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

enter image description here

Nothing else needs to be changed.

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

+4
source

Source: https://habr.com/ru/post/975418/


All Articles