包含外部C库和Xcode

我有一个内置的C静态库(Antlr 3 C库)。 它被正确安装和工作(即,我可以运行gcc -o parser lexer.c parser.c -lantlr3c就好)。

在Xcode中,但是,我得到一个错误。 我在“其他链接器标记”构build设置中添加了-lantlr3c

 ld: library not found for -lantlr3c Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1 

我在这里find的其他一些问题( 1,2,3,4 )通常有针对Xcode 3的答案。我在iOS静态库项目中使用Xcode 4.1。 我目前正在build立unit testing的东西。


编辑:按照@LaceySnr的要求,输出从详细的海湾合作委员会和Xcode的错误。

gcc的输出:

 $ gcc -v -o parser.o BFMathParser.c BFMathLexer.c -lantlr3c -arch i386 Using built-in specs. Target: i686-apple-darwin11 Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/src/configure --disable-checking --enable-werror --prefix=/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1 Thread model: posix gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00) /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/cc1 -quiet -v -iprefix /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/ -D__DYNAMIC__ BFMathParser.c -fPIC -quiet -dumpbase BFMathParser.c -mmacosx-version-min=10.7.0 -mtune=core2 -auxbase BFMathParser -version -o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccistonB.s ignoring nonexistent directory "/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include" ignoring nonexistent directory "/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include" #include "..." search starts here: #include <...> search starts here: /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/include /usr/local/include /Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. GNU C version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00) (i686-apple-darwin11) compiled by GNU C version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00). GGC heuristics: --param ggc-min-expand=150 --param ggc-min-heapsize=131072 Compiler executable checksum: edef36ecca2ce3f93d0f78610b5af911 /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/as -arch i386 -force_cpusubtype_ALL -o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccqP9bOO.o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccistonB.s /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/cc1 -quiet -v -iprefix /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/ -D__DYNAMIC__ BFMathLexer.c -fPIC -quiet -dumpbase BFMathLexer.c -mmacosx-version-min=10.7.0 -mtune=core2 -auxbase BFMathLexer -version -o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccistonB.s ignoring nonexistent directory "/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include" ignoring nonexistent directory "/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include" #include "..." search starts here: #include <...> search starts here: /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/include /usr/local/include /Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. GNU C version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00) (i686-apple-darwin11) compiled by GNU C version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00). GGC heuristics: --param ggc-min-expand=150 --param ggc-min-heapsize=131072 Compiler executable checksum: edef36ecca2ce3f93d0f78610b5af911 /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/as -arch i386 -force_cpusubtype_ALL -o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccepo2q0.o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccistonB.s /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/collect2 -dynamic -arch i386 -macosx_version_min 10.7.0 -weak_reference_mismatches non-weak -o parser.o -lcrt1.10.6.o -L/usr/lib/i686-apple-darwin11/4.2.1 -L/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1 -L/usr/llvm-gcc-4.2/bin/../lib/gcc -L/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1 -L/usr/lib/gcc/i686-apple-darwin11/4.2.1 -L/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/../../.. -L/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../.. /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccqP9bOO.o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccepo2q0.o -lantlr3c -lSystem -lgcc -lSystem 

Xcode的输出:

 Libtool /Users/bf/Library/Developer/Xcode/DerivedData/Calculator-dggaoccanosfnrampxhlfrbuuyoi/Build/Products/Debug-iphonesimulator/libcalclib.a normal i386 cd /Users/bf/Desktop/calclib setenv MACOSX_DEPLOYMENT_TARGET 10.6 setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool -static -arch_only i386 -syslibroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -L/Users/bf/Library/Developer/Xcode/DerivedData/Calculator-dggaoccanosfnrampxhlfrbuuyoi/Build/Products/Debug-iphonesimulator -filelist /Users/bf/Library/Developer/Xcode/DerivedData/Calculator-dggaoccanosfnrampxhlfrbuuyoi/Build/Intermediates/calclib.build/Debug-iphonesimulator/calclib.build/Objects-normal/i386/calclib.LinkFileList -lantlr3c -ObjC -framework Foundation -o /Users/bf/Library/Developer/Xcode/DerivedData/Calculator-dggaoccanosfnrampxhlfrbuuyoi/Build/Products/Debug-iphonesimulator/libcalclib.a Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool failed with exit code 1 

在导航器中单击您的项目,select适当的目标,然后展开“ 链接的框架和库”部分。 单击加号,单击添加其他… ,然后浏览到您的静态对象。

你也必须删除-lantlr3c标志。

您可以在其他链接器标志中使用它,但是也需要确保path在库searchpath中。

还要确保你正在构build正确的configuration(debugging/释放/无论) – 你可以指定不同的库链接每一个,所以如果你已经设置为debugging,但你正在build设释放它显然不会链接。

当你在你的Mac上用gcctesting这个库时,你正在使用它的x86版本。 iOS连接器没有find它,因为您可能没有构build库的arm版本。