xcode 项目中的错误:ld:找不到 -lcrt1.10.6.o 的库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1365211/
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
Error in xcode project: ld: library not found for -lcrt1.10.6.o
提问by kindaran
Just upgraded to Snow Leopard, installed Xcode 3.2, then installed iPhone SDK 3 for SL.
刚刚升级到雪豹,安装了 Xcode 3.2,然后安装了 iPhone SDK 3 for SL。
In a project, I now get the following error on build:
在一个项目中,我现在在构建时收到以下错误:
ld
: library not found for-lcrt1.10.6.o
ld
: 未找到库-lcrt1.10.6.o
I've searched around the net, but nothing helpful can be found.
我在网上搜索过,但找不到任何有用的东西。
回答by kindaran
Edit Project Settings -> In the build tab -> For Mac OS X Deployment Target, change it to 10.5 for XCode 3 (not 10.6 even if on 10.6) and see if that helps.
编辑项目设置 -> 在构建选项卡 -> 对于 Mac OS X 部署目标,将 XCode 3 的值更改为 10.5(即使在 10.6 上也不是 10.6),看看是否有帮助。
For XCode 4, you'll need to set it to 10.6
对于 XCode 4,您需要将其设置为 10.6
P.S. Make sure you set that for all targets, not just release or debug. (if you didn't, one would fail, the other wouldn't)
PS 确保为所有目标设置,而不仅仅是发布或调试。(如果你不这样做,一个会失败,另一个不会)
回答by Stefan
Add the following to ~/.profile (for Mac OS X 10.5):
将以下内容添加到 ~/.profile(对于 Mac OS X 10.5):
export C_INCLUDE_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/include
export LIBRARY_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/lib
回答by Stefan
I was able to fix this problem by adding the following to my Makefile:
我能够通过将以下内容添加到我的 Makefile 来解决这个问题:
CFLAGS="$(OTHER_CFLAGS) -mmacosx-version-min=10.5"
LDFLAGS="$(OTHER_LDFLAGS) -mmacosx-version-min=10.5"
Ostensibly, this is only required when building outside of Xcode. This problem frustrated me long enough that I figured it would be useful to share my experience here.
表面上,这仅在 Xcode 之外构建时才需要。这个问题让我很沮丧,我认为在这里分享我的经验会很有用。
回答by Lily Ballard
It looks like you're picking up libraries from /usr/lib, which is wholly inappropriate for the iPhone SDK. I would assume you've changed your build settings to add /usr/lib to the library search paths. This should be completely unnecessary in the first place, as /usr/lib is in the compiler's standard search paths, but if you need to have a modified search path like this, make sure to use $(SDKROOT)/usr/lib
instead.
看起来您正在从 /usr/lib 中获取库,这完全不适合 iPhone SDK。我假设您已更改构建设置以将 /usr/lib 添加到库搜索路径。首先这应该是完全没有必要的,因为 /usr/lib 位于编译器的标准搜索路径中,但是如果您需要像这样修改搜索路径,请确保改为使用$(SDKROOT)/usr/lib
。
回答by kenorb
The compiler normally uses crt1.o
combined with crt[i/n].o and crt[begin/end].o to support the constructors and destructors (functions called before and after main and exit).
编译器通常crt1.o
结合使用 crt[i/n].o 和 crt[begin/end].o 来支持构造函数和析构函数(在 main 和 exit 之前和之后调用的函数)。
This error could be caused by this missing library file for the specific deployment target.
此错误可能是由于特定部署目标的此库文件丢失所致。
First, do some investigation, like:
首先,做一些调查,例如:
List all your deployment targets:
ls -la /Developer/SDKs
Find which
crt1
libraries do you have for which environmentfind /Developer/SDKs -name crt1\*
You could see something like:
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.10.5.o /Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.o /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.5.o /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.o
列出所有部署目标:
ls -la /Developer/SDKs
查找
crt1
您在哪种环境下拥有哪些库find /Developer/SDKs -name crt1\*
你可以看到类似的东西:
/Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.10.5.o /Developer/SDKs/MacOSX10.5.sdk/usr/lib/crt1.o /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.5.o /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.o
As you can see in above example, crt1.10.6.o
is missing for MacOSX10.5.
正如您在上面的示例中看到的,crt1.10.6.o
MacOSX10.5 缺少。
Solution 1
解决方案1
You can solve that by creating the link to the missing file pointed to the other environment, or you could change your deployment target. E.g.
您可以通过创建指向其他环境的缺失文件的链接来解决该问题,或者您可以更改部署目标。例如
ln -s /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o /Developer/SDKs/MacOSX10.5.sdk/usr/lib/
Other reason why it's missing, is that you could have different gcc
installed in your system. E.g.:
它丢失的另一个原因是gcc
您的系统中可能安装了不同的版本。例如:
which gcc
xcrun -find gcc
brew list | grep gcc; brew list gcc47
Solution 2
解决方案2
So when you're compiling using make, you can actually specify the right compiler by CC variable. E.g.
因此,当您使用 make 进行编译时,您实际上可以通过 CC 变量指定正确的编译器。例如
CC=/path/to/gcc-3.4 make
Solution 3
解决方案3
What you can also try is specifying the right target deployment environment variable for gcc, e.g.:
您还可以尝试为 gcc 指定正确的目标部署环境变量,例如:
export MACOSX_DEPLOYMENT_TARGET=10.5
If this works, then you can add this library path to your shell profile (~/.profile
).
E.g.
如果可行,那么您可以将此库路径添加到您的 shell 配置文件 ( ~/.profile
)。例如
export C_INCLUDE_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/include
export LIBRARY_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/lib
Or by temporary exporting them.
或者通过临时导出它们。
How to test
如何测试
Create the example conftest.c
file with the following code:
conftest.c
使用以下代码创建示例文件:
#ifdef __GNUC__
yes;
#endif
And try to compile it via:
并尝试通过以下方式编译它:
gcc conftest.c
cc conftest.c
cc conftest.cc conftest.c
回答by ashna
Setting deployment target to compiler defaults solved the problem. Don't change anything else.
将部署目标设置为编译器默认值解决了这个问题。不要改变其他任何东西。
回答by ashna
I had the same issue in a Fortran Makefile. Added the following option after the compiler (For OSX 10.5):
我在 Fortran Makefile 中遇到了同样的问题。在编译器之后添加了以下选项(对于 OSX 10.5):
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib
-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib
e.g.,
例如,
g77 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib
g77 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib
Now the compiler will find the library you want !
现在编译器会找到你想要的库!
回答by prakash
Wasted few hours on this one...
在这个上浪费了几个小时......
Interestingly, for me the problem was only for Simulator-Debug. It wasnt complaining for Simulator-Release or Device Debug/Release!
有趣的是,对我来说,问题仅在于 Simulator-Debug。它没有抱怨模拟器发布或设备调试/发布!
anyway, Changing Deployment Target to 10.5 solved this for me!!
无论如何,将部署目标更改为 10.5 为我解决了这个问题!!
回答by beryllium
This problem solved by setting Mac OS X Deployment Target to 10.5 and after this set back to Compiler Default:)
通过将 Mac OS X 部署目标设置为 10.5,然后将其设置回编译器默认值来解决此问题 :)
回答by Ben Golding
I had this problem when I was using Xcode 4 on one machine and Xcode 3.2.6 on another. The two versions are supposed to be able to swap .xcodeproj files between them but I found that in the project.pbxproj file (inside the .xcodeproj directory), there were still a couple of places that read:
当我在一台机器上使用 Xcode 4 而在另一台机器上使用 Xcode 3.2.6 时,我遇到了这个问题。这两个版本应该能够在它们之间交换 .xcodeproj 文件,但我发现在 project.pbxproj 文件中(在 .xcodeproj 目录中),仍然有几个地方写着:
MACOSX_DEPLOYMENT_TARGET = 10.6;
MACOSX_DEPLOYMENT_TARGET = 10.6;
I quit Xcode and went and changed the three occurrences to:
我退出了 Xcode,然后将三个事件更改为:
MACOSX_DEPLOYMENT_TARGET = 10.5;
MACOSX_DEPLOYMENT_TARGET = 10.5;
After reopening the project, I could build again. Whew!
重新打开项目后,我可以再次构建。哇!