但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第三方类库)文件编译时又出现这种错误,一开始以为工程问题,但是新建工程后还是出现这个问题,经过网上查找,得到了解决办法;
- Undefined symbols for architecture i386:
- "_OBJC_CLASS_$_FMDatabase", referenced from:
- objc-class-ref in ViewController.o
- ld: symbol(s) not found for architecture i386
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
![](https://img-my.csdn.net/uploads/201304/12/1365771180_2409.png)
在网上得到解决办法是:
在工作左边导航栏Target-->Build Phases-->compile Sources中,第三库库的所有.m文件都添加到里面,然后编译通过了;
![](https://img-my.csdn.net/uploads/201304/12/1365771184_6414.png)
添加.m文件
![](https://img-my.csdn.net/uploads/201304/12/1365771189_7727.png)
根据对比可以看见 in FMDBTest,FMDBTest的Target里添加进去了了一些.m文件
![](https://img-my.csdn.net/uploads/201304/12/1365771194_9527.png)
三、如果报这种错
这样的错误怎么解决???
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中添加这个库就好。