链接二进制与xcconfig中的静态库 [英] Link binary with static library in xcconfig

查看:182
本文介绍了链接二进制与xcconfig中的静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xcode项目,本质上是一个单一的应用程序,内置几个几乎相同的目标。我已经移动了几乎所有的构建配置设置在中心位置,但我不知道如何将链接静态库(libMantle.a)移动到xcconfig。我试过 -framework -l <​​/ code>标志,像我用于其他各种库,但他们不工作。有没有办法从链接二进制文件中获取.a文件与库窗格,所以我不需要手动同步所有的目标?

解决方案

想象出来...



假设您想要链接文件 libGoogleAnalyticsServices.a 。在.xcconfig中基本上有三件事情可以让它工作。



首先,你要确保你的搜索路径中有库的路径。然后,您需要传递两个标记以使链接器开始 -L 与目录的路径, -l



<$>



<$>

p $ p> LIBRARY_SEARCH_PATHS = $(继承)$(SRCROOT)/供应商/ Google Analytics(分析)
OTHER_LDFLAGS = $(继承)-L$(SRCROOT)/供应商/ -lGoogleAnalyticsServices

(您需要调整相对路径) / p>

最有帮助的事情是日志导航器(Xcode中的命令+ 8)。通过将静态库放在构建阶段 Link Binary With Libraries 面板中并执行成功构建,您可以查看日志中链接器步骤的详细信息,将Google Analytics(分析)库传递给编译器。从那里只是复制这些标志在xcconfig。


I have an Xcode project that is essentially a single app that gets built into several almost identical targets. I have moved nearly all build configuration settings in central places, but I cannot figure out how to move linking against a static library (libMantle.a) to the xcconfig. I have tried the -framework and -l flags, like I'm using for various other libraries, but they don't work. Is there a way to get .a files out of the Link Binary with Libraries pane, so I don't need to keep all the targets in sync manually?

解决方案

Figured it out...

Let's say you want to link against the file libGoogleAnalyticsServices.a. There are basically three things you should have in your .xcconfig to get it working.

First you want to make sure you have the path to the library in your search path. Then you need to pass two flags to make the linker happy -L with the path to the directory, and -l with the library.

Putting it all together will get you something like:

LIBRARY_SEARCH_PATHS = $(inherited) "$(SRCROOT)/Vendor/Google Analytics"
OTHER_LDFLAGS = $(inherited) -L"$(SRCROOT)/Vendor/Google Analytics" -lGoogleAnalyticsServices

(You would need to adjust for your relative paths)

The most helpful thing in getting this sorted out was the Log Navigator (command+8 in Xcode). By putting the static library in the Build Phases Link Binary With Libraries panel and doing a successful build, you can look details of the linker step in the logs, and see how it was passing the Analytics library to the compiler. From there it's just replicating those flags in the xcconfig.

这篇关于链接二进制与xcconfig中的静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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