命令行库构建因链接器错误而失败 [英] command-line library build fails with linker error

查看:135
本文介绍了命令行库构建因链接器错误而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用脚本使用XCode 4.3获取库未找到错误构建GraphViz当前版本(2012年6月7日)。我可能犯了错误,更新构建脚本来自其他人对XCode4.3的新位置和Application文件夹中的开发人员工具的成功配方。

I am getting a library not found error building GraphViz current release (June 7 2012) with XCode 4.3 using a script. I may have made mistakes updating build scripts from other people's successful recipes for the new location of XCode4.3 and the developer tools in the Application folder.

ld:找不到-lcrt1.10.6.o的库

(从内存中执行此操作,因此CRT lib上的确切数字可能是错误的)

(doing this from memory so exact number on the CRT lib may be wrong)

我也有点迷失了如何将它合并到
IDE中的XCode构建中。我是一个非常有经验的程序员,但有时很难找到XCode 4的方法。 (几十年的Visual Studio等)。

Am also a little lost also how I would incorporate this into an XCode build in th IDE. I am a very experienced programmer but having trouble finding my way around XCode 4 at times. (Decades of Visual Studio et al).

我复制了来自这个早先的问题并改编了

#!/bin/sh
# For iPhoneOS, see http://clang.llvm.org/ for options
export DEV_iOS=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
# was /Developer/Platforms/iPhoneOS.platform/Developer
export SDK_iOS=${DEV_iOS}/SDKs/iPhoneOS5.1.sdk
export COMPILER_iOS=${DEV_iOS}/usr/bin
export CC=${COMPILER_iOS}/clang
export CXX=${COMPILER_iOS}/clang++
export LDFLAGS="-arch armv7 -pipe -Os -gdwarf-2 -mthumb -isysroot ${SDK_iOS}"
export CFLAGS="${LDFLAGS}"
export OBJCFLAGS="${LDFLAGS}"
export CXXFLAGS="${LDFLAGS} -fvisibility-inlines-hidden"
export LD=${COMPILER_iOS}/ld
export CPP=${COMPILER_iOS}/clang
export AR=${COMPILER_iOS}/ar
export AS=${COMPILER_iOS}/as
export NM=${COMPILER_iOS}/nm
export CXXCPP="${COMPILER_iOS}/clang++"
export OBJC=${COMPILER_iOS}/clang
export RANLIB=${COMPILER_iOS}/ranlib

./configure \
--build=arm-apple-darwin11 \
--host=arm-apple-darwin11 \
--disable-dependency-tracking \
--enable-shared=no \
--enable-static=yes \
--enable-ltdl=no \
--enable-swig=no \
--enable-tcl=no \
--srcdir=${GVROOT} \
--with-codegens=no \
--with-cgraph=no \
--with-graph=yes \
--with-expat=no \
--with-fontconfig=no \
--with-freetype2=no \
--with-ipsepcola=yes \
--with-libgd=no \
--with-quartz=yes \
--with-visio=yes \
--with-x=no


推荐答案

编译器通常使用crt1.o结合crt [i / n] .o和crt [begin / end] .o来支持构造函数和破坏ors(在main和exit之前和之后调用的函数)。

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).

此错误可能是由于缺少特定部署目标的库文件引起的。

This error could be caused by this missing library file for the specific deployment target.

首先,做一些调查,例如:

First, do some investigation, like:


  1. 列出所有部署目标:

  1. list all your deployment targets:

ls -la / Developer / SDKs

找到哪个crt1库有哪些环境

and find which crt1 libraries do you have for which environment

find / 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

所以你可以看到,MacOSX10.5缺少crt1.10.6.o。

So as you can see, crt1.10.6.o is missing for MacOSX10.5.

解决方案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/






这也可能是因为您的系统中安装了不同的gcc。请参阅:


Also this could be caused, that you have different gcc installed in your system. See:

哪个gcc;

xcrun -find gcc;

brew list | grep gcc; brew list gcc47

解决方案2

所以当您使用make进行编译时,您实际上可以通过CC变量指定正确的编译器。例如

So when you're compiling using make, you can actually specify the right compiler by CC variable. E.g.

CC=/path/to/gcc-3.4 make






解决方案3

您还可以尝试通过执行以下行为gcc指定正确的目标部署环境变量:

What you can also try is specifying the right target deployment environment variable for gcc, by executing the following lines:

export MACOSX_DEPLOYMENT_TARGET=10.5
export C_INCLUDE_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/include
export LIBRARY_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/lib

如果这样可行,那么您可以将以上行添加到您的shell配置文件(〜/ .profile)以使更改成为永久更改。

If this works, then you can add above lines to your shell profile (~/.profile) to make the change permanent.

如何测试

创建示例 conftest.c 包含以下代码的文件:

Create the example conftest.c file with the following code:

#ifdef __GNUC__
  yes;
#endif

并尝试通过以下方式编译:

And try to compile it via:

gcc conftest.c
cc conftest.c
cc conftest.cc conftest.c

疑难解答

要查看哪个文件丢失了,尝试使用dtruss调试它,例如:

To see which exactly what file is missing, try to debug it using dtruss, e.g.:

sudo dtruss -f gcc conftest.c 2>/dev/stdout | grep crt

你应该看到类似的东西:

You should see something like:

12426/0xb4e3b:  stat64("/Developer/usr/lib/gcc/i686-apple-darwin10/4.2.1/crt1.10.6.o\0", 0x7FFF5FBFE780, 0xB)        = -1 Err#2

所以一旦找到丢失的文件,那么你可以按照通过链接现有位置的丢失文件的第一个解决方案(例如 locate crt1.10.6.o )。如果你有其他缺少的符号,那么尝试另一个文件(检查之前的架构:文件`locate crt1.10.6.o` )。

So once you found the missing file, then you can follow by the first solution by linking the missing file from existing location (e.g. locate crt1.10.6.o). If you will have other missing symbols, then try another file (check the architecture before by: file `locate crt1.10.6.o`).

例如

sudo ln -s /Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/crt1.10.6.o /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/crt1.10.6.o
sudo ln -s /Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib/crt1.10.6.o /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/crt1.10.6.o






相关

xcode项目出错:ld:找不到-lcrt1.10.6.o的库

这篇关于命令行库构建因链接器错误而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆