linker command failed with exit code

参考地址:http://blog.csdn.net/kaizi318/article/details/10362455
http://code4app.com/requirement/51bc27476803fae35c000001

解决XCode编译错误clang: error: linker command failed with exit code 1,_SCNetworkReachabilityCreateWithAddress", referenced from


但iPhone5编译出现以下错误:clang: error: linker command failed with exit code 1 (use -v to see invocation)



一、

把 Valid Architectures  的值改为 armv7

过程:

PROJECT --> Build Settings --> Architectures --> Valid Architectures  他的值本来是 armv7 armv7s ,把armv7s 去掉即可

同样的操作

TARGETS -->  Build Settings --> Architectures --> Valid Architectures  做同样的修改

二、

以上修改如果还不行,继续

PROJECT --> Build Settings --> Architectures -->Build Active Architecture Only的值改变No

同样操作

TARGETS --> Build Settings --> Architectures -->Build Active Architecture Only的值改变No


Apple Mach-O Linker Error
是一类错误,错误信息的最后一行,通常如下
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang failed with exit code 1

发生这种错误的原因通常是因为两个子工程中存在同名类造成的链接错误。
比如我发生错误的原因就是因为在两个.m文件中都定义了同样名字的const变量。

虽然给的错误信息不明显,但是点开还是可以发现一些信息,从而定位的。但是信息很多,需要仔细排查,这次就是在众多的信息中发现了那个变量的命名,从而找到这个问题,通常你的变量都会被加一些前后缀显示。

  linker command failed with exit code 1 (use -v to see invocation)这个错误貌似遇见并不止一次,当我想用某个第三方类库的时候(如SBJson),我直接把类库文件copy到工程目录里面,然后一编译就出现这样错误(并不是一定会出这样错误),开始以为是网上下载的类库本身问题,所以重新找类库或者其他方式将它添加进去,只要不出错就行,也一直没有深入了解根本问题,今天在给工程添加一个FMDB(SQLIte第三方类库)文件编译时又出现这种错误,一开始以为工程问题,但是新建工程后还是出现这个问题,经过网上查找,得到了解决办法;


[cpp]  view plain copy
  1. Undefined symbols for architecture i386:  
  2.   "_OBJC_CLASS_$_FMDatabase", referenced from:  
  3.       objc-class-ref in ViewController.o  
  4. ld: symbol(s) not found for architecture i386  
  5. clang: error: linker command failed with exit code 1 (use -v to see invocation)  




在网上得到解决办法是:

在工作左边导航栏Target-->Build Phases-->compile Sources中,第三库库的所有.m文件都添加到里面,然后编译通过了;




添加.m文件



根据对比可以看见 in FMDBTest,FMDBTest的Target里添加进去了了一些.m文件



三、如果报这种错

这样的错误怎么解决??? 

Undefined symbols for architecture i386: 
"_SCError", referenced from: 
-[Reachability startNotifier] in Reachability.o 
"_SCErrorString", referenced from: 
-[Reachability startNotifier] in Reachability.o 
"_SCNetworkReachabilityCreateWithAddress", referenced from: 
+[Reachability reachabilityWithAddress:] in Reachability.o 
"_SCNetworkReachabilityCreateWithName", referenced from: 
+[Reachability reachabilityWithHostname:] in Reachability.o 
"_SCNetworkReachabilityGetFlags", referenced from: 
-[Reachability isReachable] in Reachability.o 
-[Reachability isReachableViaWWAN] in Reachability.o 
-[Reachability isReachableViaWiFi] in Reachability.o 
-[Reachability connectionRequired] in Reachability.o 
-[Reachability isConnectionOnDemand] in Reachability.o 
-[Reachability isInterventionRequired] in Reachability.o 
-[Reachability reachabilityFlags] in Reachability.o 
... 
"_SCNetworkReachabilitySetCallback", referenced from: 
-[Reachability startNotifier] in Reachability.o 
-[Reachability stopNotifier] in Reachability.o 
"_SCNetworkReachabilitySetDispatchQueue", referenced from: 
-[Reachability startNotifier] in Reachability.o 
-[Reachability stopNotifier] in Reachability.o 
ld: symbol(s) not found for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation)

那就是没有引入 SystemConfiguration.framework框架,在target-Build Phases-link Binary with Library中添加这个库就好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值