在XCode编译iOS应用时出现“文件未找到:-fobjc-arc”错误

7
在添加OCMock框架后,我收到了一个奇怪的错误信息... :(
ld: 文件未找到:-fobjc-arc
clang: 错误:链接器命令失败,退出码为 1(使用 -v 查看调用过程)
看起来好像编译器标志被XCode加载了?
有什么想法吗?
最好的问候,hijolan

1
你使用的Xcode版本是什么? - Shaggy Frog
查看日志导航器中的构建输出。如果您无法弄清楚,请在此处发布。 - trojanfoe
嗨...感谢您的回复...上面的代码来自日志导航器...我现在通过Git还原了我的项目文件并重新添加了库.. ;) 现在它可以工作了。 - monavari-lebrecht
我现在遇到了这个错误 - 我已经编辑了问题并添加了日志导航器输出。 - makdad
1个回答

10

我在Xcode 4.3.2上也遇到了完全相同的错误。这是我的导航日志,我为了增加谷歌搜索排名而添加它。

Ld /Users/makdad/Library/Developer/Xcode/DerivedData/Journal-bfkvfbsrkmrsjpddzfmwrstjfkzr/Build/Products/Debug-iphonesimulator/JournalTests.octest/JournalTests normal i386
cd /Users/makdad/Documents/MT/mt-mobile/iOS/Journal
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -bundle -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -L/Users/phooze/Library/Developer/Xcode/DerivedData/Journal-bfkvfbsrkmrsjpddzfmwrstjfkzr/Build/Products/Debug-iphonesimulator -F/Users/phooze/Library/Developer/Xcode/DerivedData/Journal-bfkvfbsrkmrsjpddzfmwrstjfkzr/Build/Products/Debug-iphonesimulator -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/Developer/Library/Frameworks -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks -filelist /Users/phooze/Library/Developer/Xcode/DerivedData/Journal-bfkvfbsrkmrsjpddzfmwrstjfkzr/Build/Intermediates/Journal.build/Debug-iphonesimulator/JournalTests.build/Objects-normal/i386/JournalTests.LinkFileList -mmacosx-version-min=10.6 -bundle_loader /Users/phooze/Library/Developer/Xcode/DerivedData/Journal-bfkvfbsrkmrsjpddzfmwrstjfkzr/Build/Products/Debug-iphonesimulator/Journal.app/Journal -Xlinker -objc_abi_version -Xlinker 2 -ObjC -force_load -fobjc-arc -ftest-coverage -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -lOCMock -framework Twitter -framework MapKit -framework MobileCoreServices -framework SystemConfiguration -lxml2 -licucore -framework CoreData -framework CoreGraphics -framework CFNetwork -framework QuartzCore -framework SenTestingKit -framework UIKit -framework Foundation -o /Users/phooze/Library/Developer/Xcode/DerivedData/Journal-bfkvfbsrkmrsjpddzfmwrstjfkzr/Build/Products/Debug-iphonesimulator/JournalTests.octest/JournalTests
OCMock的说明明确要求你添加链接器标志——-ObjC-force_load-force_load需要一个值--请参考这个问题的答案,解释了如果您不想指定库名称应该使用-all_load
作为一个刚刚花了25分钟的人,我应该再次查看OCMock教程--我认为这个指令并不是非常清晰。 这篇博客文章有一张更好的图片,可以准确地展示您的设置应该是什么样子的。

2
作为一条注意事项,-all_load-force_load在Xcode 4.2及更高版本的LLVM中不再必要:https://dev59.com/41zUa4cB1Zd3GeqP57dX#7942924。曾经由于链接器错误而需要它们,但是这个问题已经在最新版本的LLVM中得到解决。您应该能够放弃除`-ObjC`之外的链接器标志。 - Brad Larson
2
@BradLarson 感谢澄清。这总是发生的事情...人们添加巫术魔法来解决错误,但当错误被修复后,没有人会四处“清理”旧的解决方法帖子的混乱。 - makdad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接