gpt4 book ai didi

ios - 有条件地链接 iOS 上的库

转载 作者:可可西里 更新时间:2023-11-01 04:42:04 28 4
gpt4 key购买 nike

我想有条件地链接一个库(我有这个用于 iOS 设备的库,但我没有用于模拟器的库)。我正在使用 Xcode 4.6 和 iOS 6.1。

我读了一个问题(和一些类似的问题):iOS conditional link static library

-weak_library 链接器标志

我尝试使用以下标志构建项目:

-weak_library LibraryNameWithPath

但是它给了我一个错误:

ld: file not found: LibraryNameWithPath

-weak-l 链接器标志

我尝试使用以下标志构建它:

-weak-lShortLibraryName

得到相同的结果:

ld: library not found for -lShortLibraryName

想法

到底为什么,它是否检查库是否存在,如果它被明确标记为弱链接?

有没有办法在构建时进行条件链接(对比 dlopen、dlclose 和 friend 的运行时使用)?

最佳答案

我实际上并没有尝试直接使用构建标志来执行此操作,但我已经使用 Xcode GUI 设置完成了它。选择您的构建目标,然后选择构建阶段,然后选择将您的静态库添加到要链接的二进制文件列表中。

但是,从右侧的必需/可选菜单中选择可选(这不是默认设置)。

enter image description here

由于这是您正在谈论的静态库,我认为您需要在代码中放置一些预处理器保护程序,以禁止在模拟器中使用该库:

#if TARGET_IPHONE_SIMULATOR
NSLog(@"do nothing here!");
#else
HelloLibrary* hl = [[HelloLibrary alloc] init];
NSString* result = [hl helloLibraryFoo];
#endif

什么都没做来完成这项工作(没有修改其他build设置)。

在为模拟器构建时,我只收到此警告:

ld: warning: ignoring file /Users/me/Desktop/code/MyAppName/libHelloLibrary.a, file was built for archive which is not the architecture being linked (i386): /Users/me/Desktop/code/MyAppName/libHelloLibrary.a

关于ios - 有条件地链接 iOS 上的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15794094/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com