命令行库构建因链接器错误而失败

时间:2012-06-07 23:27:33

标签: ios5 xcode4.3 graphviz

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

ld: library not found for -lcrt1.10.6.o

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

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

我复制了this earlier question的说明并改编了

#!/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

2 个答案:

答案 0 :(得分:1)

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

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

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

  1. 列出所有部署目标:

    ls -la /Developer/SDKs

  2. 找到哪个crt1库有哪些环境

    find /Developer/SDKs -name crt1\*

  3. 您可以看到类似的内容:

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

    解决方案1:

    您可以通过创建指向其他环境的丢失文件的链接来解决此问题,也可以更改部署目标。 E.g。

    ln -s /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.10.6.o /Developer/SDKs/MacOSX10.5.sdk/usr/lib/
    

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

    which gcc;

    xcrun -find gcc;

    brew list | grep gcc; brew list gcc47

    解决方案2

    因此,当您使用make进行编译时,您实际上可以通过CC变量指定正确的编译器。 E.g。

    CC=/path/to/gcc-3.4 make
    

    解决方案3

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

    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)以使更改永久化。


    如何测试

    使用以下代码创建示例conftest.c文件:

    #ifdef __GNUC__
      yes;
    #endif
    

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

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

    <强>疑难解答

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

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

    您应该看到类似的内容:

    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)来遵循第一个解决方案。如果您有其他缺少的符号,请尝试另一个文件(在file `locate crt1.10.6.o`之前检查架构。)

    E.g。

    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
    

    相关

    Error in xcode project: ld: library not found for -lcrt1.10.6.o

答案 1 :(得分:0)

如果我没记错的话,这就解决了找不到库的问题。

CFLAGS="$(OTHER_CFLAGS) -miphoneos-version-min=5.0"
LDFLAGS="$(OTHER_LDFLAGS) --miphoneos-version-min=5.0"

要将其链接到Xcode,请在“构建设置”下,然后在“标题和库”搜索路径中添加路径到库的内置版本和标题。

你可以添加构建脚本作为Xcode项目的一部分,但是我没有成功使用它,而且你应该只需要为每个版本构建一次,所以把时间放在除了构建脚本之外的任何东西上都没有没有多少回报。

如果您决定将脚本放入项目中(祝您好运!),请转到构建阶段选项卡,添加“运行脚本”类型的构建阶段并将脚本粘贴到那里。