找不到 -lobjc 的 xcode 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19720595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:14:26  来源:igfitidea点击:

xcode library not found for -lobjc

iosobjective-cxcode

提问by Kian Ping

I am getting this error when I am trying to run it on my device, however it working fine when I run it on simulator. Is this a tool chain error or SDK header error? Below is the error message I obtain when compiling.

当我尝试在我的设备上运行它时出现此错误,但是当我在模拟器上运行它时它工作正常。这是工具链错误还是 SDK 头错误?下面是我编译时得到的错误信息。

Error Message:

错误信息:

Ld /Users/KhangYu/Library/Developer/Xcode/DerivedData/mobiletimetec-bbuzqjqgmijmomgdmvebkbyasqii/Build/Intermediates/mobiletimetec.build/Debug-iphoneos/mobiletimetec.build/Objects-normal/armv7/mobiletimetec normal armv7
    cd /Users/KhangYu/Desktop/KPTesting/setting
    setenv IPHONEOS_DEPLOYMENT_TARGET 6.1
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.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 armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -L/Users/KhangYu/Library/Developer/Xcode/DerivedData/mobiletimetec-bbuzqjqgmijmomgdmvebkbyasqii/Build/Products/Debug-iphoneos -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib/system -F/Users/KhangYu/Library/Developer/Xcode/DerivedData/mobiletimetec-bbuzqjqgmijmomgdmvebkbyasqii/Build/Products/Debug-iphoneos -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks -filelist /Users/KhangYu/Library/Developer/Xcode/DerivedData/mobiletimetec-bbuzqjqgmijmomgdmvebkbyasqii/Build/Intermediates/mobiletimetec.build/Debug-iphoneos/mobiletimetec.build/Objects-normal/armv7/mobiletimetec.LinkFileList -dead_strip -fobjc-arc -fobjc-link-runtime -miphoneos-version-min=6.1 -framework SystemConfiguration -framework AVFoundation -lsqlite3.0 -framework MapKit -framework CoreLocation -framework MessageUI -framework QuartzCore -framework Security -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/KhangYu/Library/Developer/Xcode/DerivedData/mobiletimetec-bbuzqjqgmijmomgdmvebkbyasqii/Build/Intermediates/mobiletimetec.build/Debug-iphoneos/mobiletimetec.build/Objects-normal/armv7/mobiletimetec


ld: library not found for -lobjc
clang: error: linker command failed with exit code 1 (use -v to see invocation)

//-- END --

// - 结尾 -

This is going to be the death of me. Any idea on how to solve it? Your help will be greatly appreciated.

这将是我的死亡。关于如何解决它的任何想法?对你的帮助表示感谢。

Thanks in advance.

提前致谢。

Solution

解决方案

Thanks Kevin and Jasper Blues reply and also thanks Reno Jones to edit my post. After hours of trying to fix this, I renamed the file "libobjc.A.dylib" to "libobjc.dylib"and the error disappear. P/S: "libobjc.A.dylib" - located in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer??/SDKs/*/usr/lib/, thanks again to Kevin.

感谢 Kevin 和 Jasper Blues 的回复,也感谢 Reno Jones 编辑我的帖子。经过数小时的尝试解决此问题后,我将文件“libobjc.A.dylib”重命名为“libobjc.dylib”,错误消失了。P/S: "libobjc.A.dylib" - 位于 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer??/SDKs/*/usr/lib/,再次感谢 Kevin。

回答by Jasper Blues

My guess is that it works on the Simulator, but not the device because you've specified separate 'OTHER LINKER FLAGS' for both 'Debug' and 'Release' configurations. You'd usually do this if you're linking in a debug framework such as 'Reveal', 'DCIntrospect', etc.

我的猜测是它适用于模拟器,但不适用于设备,因为您已经为“调试”和“发布”配置指定了单独的“其他链接器标志”。如果您在诸如“Reveal”、“DCIntrospect”等调试框架中进行链接,通常会这样做。

The one for 'Release' looks to be incorrect. It should be '-Objc' and not '-lObjc' - we're telling the compiler that we're using Objective-C itself, and not to load a library called 'Objc'.

'Release' 的那个看起来不正确。它应该是 '-Objc' 而不是 '-lObjc' - 我们告诉编译器我们正在使用 Objective-C 本身,而不是加载名为 'Objc' 的库。

To correct:

纠正:

  • In Xcode, click on the target for your App.
  • Open the 'Build Settings' tab.
  • Search for 'Other linker flags' - so you're not overwhelmed by options.
  • Correct the 'Release' config. Change '-lObjc' to '-Objc'
  • 在 Xcode 中,单击应用程序的目标。
  • 打开“构建设置”选项卡。
  • 搜索“其他链接器标志” - 这样您就不会被选项所淹没。
  • 更正“发布”配置。将“-lObjc”更改为“-Objc”

flags

旗帜

回答by Roger

There is no need to rename "libobjc.A.dylib", just re-link it like : ln -s ./libobjc.A.dylib ./libobjc.dylib

不需要重命名“libobjc.A.dylib”,只需像这样重新链接它: ln -s ./libobjc.A.dylib ./libobjc.dylib