Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

ios5 - command-line library build fails with linker error

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: library not found for -lcrt1.10.6.o

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

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. list all your deployment targets:

    ls -la /Developer/SDKs

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

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

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

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

which gcc;

xcrun -find gcc;

brew list | grep gcc; brew list gcc47

Solution 2

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

Solution 3

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

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


How to test

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

Troubleshooting

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

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

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

Related

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...