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

风格不统一 提交于 2019-12-17 16:36:30

问题


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

回答1:


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:

Nothing else needs changing.

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



来源:https://stackoverflow.com/questions/25889914/can-the-objc-flag-be-applied-selectively-to-static-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!