
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_CLLocationManager",referenced from: objc-class-ref in MySDK(MyServerConnection.o)ld: symbol(s) not found for architecture x86_64clang: error: linker command Failed with exit code 1 (use -v to see invocation)
是否有可能避免这种情况,因为我不想强迫开发人员将CoreLocation包含在他们的项目中?实际上,我知道这是可能的,但我该怎么做呢?
解决方法 从您的问题描述中,我假设您已经知道如何将 make Xcode weakly link against the framework设置为“可选”.您有两个问题需要解决:类可用性和符号可用性. Apple在Framework Programming Guide: Frameworks and Weak Linking和SDK Compatibility Guide: Using SDK Based Development中介绍了这一点
课程可用性
这非常简单:使用NSClassFromString()来查看该类是否在当前环境中可用.
if (NSClassFromString("CLLocationManager") != NulL){ 如果该类可用,则可以实例化并发送消息,否则不能.
符号可用性
您特别感兴趣的是使用来自弱链接框架的常量或结构. C风格的功能类似,但使用CoreLocation时不需要考虑这些功能.我们将使用CoreLocation常量作为示例.
每次使用它时,必须检查以确保它存在:
if (&kCLErrorDomain != NulL){ // Use the constant} 注意&获取常量的地址进行比较.
另请注意,您不能这样做:
if (kCLErrorDomain){ // Use the constant} 或这个:
if (&kCLErrorDomain){ // Use the constant} 也可以使用dlsym在运行时查找常量符号.
以这种方式使用否定运算符将不起作用.您必须根据NulL地址检查常量的地址.
I have put a very simple example of an application that is using a static library which weak links against Core Location on GitHub.示例应用程序未链接到Core Location:
但依赖性确实是一个可选的(弱)框架:
总结以上是内存溢出为你收集整理的iOS Framework弱链接:未定义符号错误全部内容,希望文章能够帮你解决iOS Framework弱链接:未定义符号错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)