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

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

问题描述

我收到一个library not found 错误,使用脚本使用 Xcode 4.3 构建 GraphViz 当前版本(2012 年 6 月 7 日).我可能在根据其他人的成功配方为 Xcode4.3 的新位置和 Applications 文件夹中的开发人员工具更新构建脚本时出错了.

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 Applications folder.

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

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

(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 the IDE. I am a very experienced programmer but having trouble finding my way around Xcode 4 at times. (Decades of Visual Studio et al).

我已从 这个较早的问题中复制了说明并进行了改编

I have copied the instructions from this earlier question and adapted

#!/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来支持构造函数和析构函数(在 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;

酿造清单 |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", 0x7FFF5FBFE780, 0xB)        = -1 Err#2

因此,一旦找到丢失的文件,您可以通过从现有位置链接丢失的文件(例如 locate crt1.10.6.o)来遵循第一个解决方案.如果您还有其他缺失的符号,请尝试另一个文件(之前检查架构:file `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天全站免登陆