-ObjC 标志可以选择性地应用于静态库吗? [英] Can the -ObjC flag be applied selectively to static libraries?

查看:21
本文介绍了-ObjC 标志可以选择性地应用于静态库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL;DR

如何使 -ObjC 链接器标志针对特定的静态库,而不是 all 我要链接的静态库,以避免链接未使用的目标文件在我的应用中?

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?

太长了;读过

因此,您正在开发一个新的 iOS 应用程序,并添加了您自己开发的objcutil"静态库,其中包含各种有用的 Objective-C 类(未实现为类别)来执行过去有用的各种事情.到目前为止,一切都很好,并且只有实用程序库中引用的那些目标文件与应用程序链接.

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.

然后您决定集成需要您的 Google Maps SDK使用 -ObjC Other Linker Flags 并且突然无法解析实用程序库中的依赖项,因为您尚未将 Xcode 配置为链接到这些库.

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?

<小时>ld 手册页中的一些参考:


Some reference from the ld manpage:

-ObjC 加载定义Objective C 类或类别的静态归档库的所有成员.此选项不适用于动态共享库.

-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 版本:5.1.1
  • OSX 版本:10.9.4
  • 推荐答案

    OK 所以答案是使用 -force_load 而不是 -ObjC 作为 -force_load 更专注.

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

    所以WRT到谷歌地图SDK,如果你按照说明将静态框架复制到app项目目录中,那么框架将在项目根目录中,你可以删除 -ObjC 来自 Other Linker Flags 并将其替换为

    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:

    没有其他需要改变的.

    对于其他库,您需要使用完整的静态库路径作为 -force_load 的参数.

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

    这篇关于-ObjC 标志可以选择性地应用于静态库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆