包括X code外部C库 [英] Including external C library with Xcode

查看:177
本文介绍了包括X code外部C库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内置C固定库(在ANTLR的3 C库)。这是正确的安装和工作(即我可以运行的gcc -o解析器lexer.c parser.c -lantlr3c 就好了)。

在X code,但是,我得到一个错误。我在其他连接标志构建设置添加 -lantlr3c

没有发现-lantlr3c库:

  LD
命令/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2失败,退出code 1

我在这里找到(<一个其他几个问题href=\"http://stackoverflow.com/questions/3344120/including-a-static-library-in-a-x$c$c-project\">1, 2 ,的3 ,<一个href=\"http://stackoverflow.com/questions/1471968/x$c$c-linker-error-library-not-found-for-ladmobdevice\">4)一般有答案瞄准X code三级。我用X code 4.1,在iOS的静态库项目。我目前正在建设的单元测试的东西。


编辑:作为的要求@LaceySnr,从冗长的gcc和X code的错误输出

从GCC的输出:

  $ gcc的-v -o parser.o BFMathParser.c BFMathLexer.c -lantlr3c -arch i386的
使用内置的规格。
目标:为i686-苹果darwin11
配置有:/private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/src/configure --disable检查--enable-werror - preFIX = /开发人员的/ usr / LLVM-GCC-4.2 - 迪尔= /共享/人--enable-语言= C,objc,C ++,OBJ-C ++ --program- preFIX = llvm- --program变换名称= / ^ [CG] [^ .-] * $ / S / $ / - 4.2 / --with-slibdir = / usr / lib目录--build = i686的 - 苹果darwin11 --enable-LLVM = /私营/ var / tmp目录/ llvmgcc42 / llvmgcc42-2335.15〜25 / DST-llvmCore /开发人员的/ usr /本地--program- preFIX = i686的 - 苹果darwin11-主机= x86_64的 - 苹果darwin11 --target = i686的 - 苹果darwin11 --with-GXX,包括 - DIR = / usr / include目录/ C ++ / 4.2.1
线程模型:POSIX
GCC 4.2.1版(基于苹果公司建立5658)(LLVM构建2335.15.00)
 /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/cc1 -quiet -v -i preFIX /usr/llvm-gcc-4.2/bin/ ../lib/gcc/i686-apple-darwin11/4.2.1/ -D__DYNAMIC__ BFMathParser.c -fPIC -quiet -dumpbase BFMathParser.c -mmacosx版本分钟= 10.7.0 -mtune = core2的-auxbase BFMathParser -version -o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccistonB.s
忽略不存在的目录/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/包括
忽略不存在的目录\"/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include\"
的#include...的搜索从这里开始:
#包括LT&; ...&GT;搜索从这里开始:
 /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/include
 在/ usr /本地/包括
 /Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include
 / usr / include目录
 /系统/库/框架(framework目录)
 /库/框架(framework目录)
搜索列表结束。
GNU C版本4.2.1(基于苹果公司建立5658)(LLVM构建2335.15.00)(i686的-苹果darwin11)
    由GNU C版本4.2.1(基于苹果公司建立5658)(LLVM建设2335.15.00)编译。
GGC启发:--param GGC-分钟展开= 150 --param GGC-最小堆大小= 131072
编译器可执行文件的校验:edef36ecca2ce3f93d0f78610b5af911
 /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/as -arch i386的-force_cpusubtype_ALL -o在/ var /文件夹/ 5V / 9rvx60c17vl7kc3b_r8gz0wc0000gn / T // ccqP9bOO。 Ø/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 -i preFIX /usr/llvm-gcc-4.2/bin/ ../lib/gcc/i686-apple-darwin11/4.2.1/ -D__DYNAMIC__ BFMathLexer.c -fPIC -quiet -dumpbase BFMathLexer.c -mmacosx版本分钟= 10.7.0 -mtune = core2的-auxbase BFMathLexer -version -o /var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccistonB.s
忽略不存在的目录/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/包括
忽略不存在的目录\"/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include\"
的#include...的搜索从这里开始:
#包括LT&; ...&GT;搜索从这里开始:
 /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/include
 在/ usr /本地/包括
 /Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include
 / usr / include目录
 /系统/库/框架(framework目录)
 /库/框架(framework目录)
搜索列表结束。
GNU C版本4.2.1(基于苹果公司建立5658)(LLVM构建2335.15.00)(i686的-苹果darwin11)
    由GNU C版本4.2.1(基于苹果公司建立5658)(LLVM建设2335.15.00)编译。
GGC启发:--param GGC-分钟展开= 150 --param GGC-最小堆大小= 131072
编译器可执行文件的校验:edef36ecca2ce3f93d0f78610b5af911
 /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/as -arch i386的-force_cpusubtype_ALL -o在/ var /文件夹/ 5V / 9rvx60c17vl7kc3b_r8gz0wc0000gn / T // ccepo2q0。 Ø/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非弱-o parser.o - lcrt1.10.6.o -L / usr / lib目录/ i686的-苹果darwin11 / -L 4.2.1的/ usr / LLVM-GCC-4.2 / bin中/../ lib中/ GCC / i686的-苹果darwin11 / 4.2.1 -L在/ usr / LLVM-GCC-4.2 / bin中/../ lib中/ gcc的-L /开发人员的/ usr / LLVM-GCC-4.2 / lib目录/ GCC / i686的-苹果darwin11 / -L 4.2.1的/ usr / LIB / GCC / i686的-苹果darwin11 / -L 4.2.1的/ usr / LLVM-GCC-4.2 / bin中/../ lib中/ GCC / i686的-苹果darwin11 / 4.2.1 /../../。 。-L /开发人员的/ usr / LLVM-GCC-4.2 / lib目录/ GCC / i686的-苹果darwin11 / 4.2.1 /../../ ..在/ var /文件夹/ 5V / 9rvx60c17vl7kc3b_r8gz0wc0000gn / T // ccqP9bOO。 Ø/var/folders/5v/9rvx60c17vl7kc3b_r8gz0wc0000gn/T//ccepo2q0.o -lantlr3c -lSystem -lgcc -lSystem

从X code中的输出:

  Libtool程序/Users/bf/Library/Developer/X$c$c/DerivedData/Calculator-dggaoccanosfnrampxhlfrbuuyoi/Build/Products/Debug-iphonesimulator/libcalclib.a正常I386
    CD /用户/ BF /桌面/ 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/X$c$c/DerivedData/Calculator-dggaoccanosfnrampxhlfrbuuyoi/Build/Products/Debug-iphonesimulator -filelist /Users/bf/Library/Developer/X$c$c/DerivedData/Calculator-dggaoccanosfnrampxhlfrbuuyoi/Build/Intermediates/calclib.build/Debug-iphonesimulator/calclib.build/Objects-normal/i386/calclib.LinkFileList -lantlr3c -ObjC -framework基金会-o /Users/bf/Library/Developer/X$c$c/DerivedData/Calculator-dggaoccanosfnrampxhlfrbuuyoi/Build/Products/Debug-iphonesimulator/libcalclib.a命令/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool失败,退出code 1


解决方案

在测试这个lib目录与海湾合作委员会在Mac上使用的是它的的x86版本。 iOS的链接器没有找到它,因为你可能没有建库的ARM版。

I have a built C static library (the Antlr 3 C library). It is installed properly and works (i.e., I can run gcc -o parser lexer.c parser.c -lantlr3c just fine).

In Xcode, however, I get an error. I've added -lantlr3c in the "other linker flags" build setting.

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

Several other questions I've found here (1, 2, 3, 4) generally have answers targeting Xcode 3. I'm using Xcode 4.1, in an iOS static library project. I'm currently building the unit test stuff.


EDIT: As requested by @LaceySnr, the output from verbose gcc and Xcode's error.

The output from 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

The output from 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

解决方案

When you test this lib with gcc on your Mac you are using the x86 version of it. The iOS linker does not find it because you probably did not build the arm version of the library.

这篇关于包括X code外部C库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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