1

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
Community
  • 1
  • 1
Cajunluke
  • 3,097
  • 27
  • 28

3 Answers3

0

Click your project in the navigator, select the appropriate target, and unfold the Linked Frameworks and Libraries section. Click the plus, click Add Other..., and browse to your static object.

You'll have to remove the -lantlr3c flag too.

zneak
  • 124,558
  • 39
  • 238
  • 307
  • I selected the test target, but I couldn't find the "Linked Frameworks and Libraries" section. I did find the "Link Binary with Libraries" section in the "Build Phases" tab, but adding the libantlr3c.a library there didn't work. (I took out the -lantlr3c flag, too, but to no avail.) – Cajunluke Sep 30 '11 at 13:51
  • I'm pretty sure I compiled it for i386, which should be good enough for now while I test in the Simulator. How would I check the library's architecture? – Cajunluke Sep 30 '11 at 20:00
  • You can use the `file` command: `file /path/to/your/file`, it will list the supported architectures of your library. – zneak Sep 30 '11 at 21:09
  • It's i386, all right. If it's the right arch and it's in the right place, why do I get the "library not found" error? – Cajunluke Sep 30 '11 at 22:00
  • @CajunLuke, what's the exact error? There shouldn't be any direct reference to the library aside from this one, and therefore if it didn't link you should get "symbol not found" errors for each function in the library, not a "library not found". – zneak Sep 30 '11 at 22:01
  • It's in the question: `ld: library not found for -lantlr3c`. If I remove the linker flag (-lantlr3c), I get all the "symbol not found" errors (as I would expect). The library is in `/usr/local/lib/` and the headers are in `/usr/local/include/`. The headers are found fine in Xcode (it even suggested them while I was coding). – Cajunluke Sep 30 '11 at 22:47
0

You can use that in the other linker flags, but you also need to make sure the path is in the library search paths too.

Also make sure you're building with the right config (debug / release / whatever) — you can specify different libraries to link for each one, so if you've set it for debug but you're building release it obviously won't link.

Matt Lacey
  • 8,077
  • 30
  • 57
  • How do I find/change the library search paths? I'm fairly certain I'm targeting the right target - test target, debug mode every time. – Cajunluke Sep 30 '11 at 13:51
  • I hadn't noticed this was for xcode 4 — have a go at using the Frame Work Search paths in your target / project settings. – Matt Lacey Oct 01 '11 at 00:36
  • I'm pretty sure it can find the library - I don't get any "symbol not found" errors, which I do get if I remove the library or the -lantlr3c flag. – Cajunluke Oct 01 '11 at 01:32
  • That's very bizarre. Best I can suggest is comparing verbose gcc output with the output from Xcode to see what might be happening differently. – Matt Lacey Oct 01 '11 at 06:05
  • I think Miguel has hit the nail on the head, see below. I always had issues when I forgot to build the device version of my libs when switching between the simulator and device for testing. – Matt Lacey Oct 02 '11 at 03:15
  • I'm only running in the simulator. I haven't even set up provisioning yet. – Cajunluke Oct 02 '11 at 14:39
0

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.

Miguel
  • 56,635
  • 12
  • 113
  • 132
  • I'm not sure how to build the library for ARM, and I'm doing testing in the iOS simulator, which builds for i386. – Cajunluke Oct 02 '11 at 14:39
  • I think you can build the ARM lib in the same way as the x86, but adding -arch armv6 or -arch armv7 to the gcc command line. – Miguel Oct 02 '11 at 16:26