Xcode and library search paths

Member
Posts: 321
Joined: 2004.10
Post: #1
This might just be a stupid Xcode user error on my part, but...

I've downloaded the libpng library (PNG file format) and I'm trying to
get an Xcode project of mine to use it. The compilation is fine, but
I get a bunch of

/usr/bin/ld: Undefined symbols:
_png_create_struct
_png_create_struct_2
_png_destroy_struct
_png_destroy_struct_2
_png_error
_png_free
_png_malloc
_png_warning

Ok, I did some googling and came across a Darwin example which used
LIBRARIES += -L/sw/lib -lpng -lz in the make file.

and looking at my "build results" there was no entry like this. So I went
into Xcode, selected my project folder and the info button. Then I selected
the build tab and the Library Search Paths collection.

I entered -L/sw/lib -lpng in the field and then left the build settings.

I recompiled and it still fails. I go into Build>Build Results and when I show
the transcript there is no -L/sw/lib -lpng string.

Anybody know why my new setting in the build options isn't making its way
to the actual build?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
because you put it in the wrong place Rasp

If you'd put those in the "other linker flags", and got libpng from fink (which is what puts it in /sw/lib) then it'd work.

Dragging libpng.a from libpng's build directory into your project should be sufficient to have Xcode do the right thing.
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #3
Thanks!

Silly me. Since libpng is a library, i thought i should've updated Search Library Path. Whatever lead me to think that Mad

Maybe one is for compile time and the other is for the link phase?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Entries in the "library search path" field have -L stuck on the front, so if you put "/sw/lib" into the library search paths, it's like adding "-L/sw/lib" to the GCC command-line.

Libraries you add to your project automatically get the "lib" knocked off the beginning and the ".a" or ".dylib" knocked off the end, and "-l" added in front, so adding libpng.a to your project is like adding "-lpng" to the GCC command-line. However, adding libpng.a to your project should automatically configure the library search paths too.
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #5
Thanks again!

I just came back from perusing the GCC web site. started to look at the documentation for gcc's options for linking and preprocessing.

There's alot of options out there Smile

Should of started here instead of Xcode's documentation.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  XCode doesn't realize a library has changed unless you force your project to build. XSTNX 6 5,468 Jun 8, 2009 10:25 AM
Last Post: XSTNX
  xcode won't link my .a library... chenjin824 0 3,397 Jun 6, 2009 07:20 PM
Last Post: chenjin824
  framework search path scarypajamas 0 3,106 Dec 23, 2008 01:50 PM
Last Post: scarypajamas
  xcode instruments screwing up paths Najdorf 4 4,365 Sep 7, 2008 02:08 PM
Last Post: OneSadCookie
  Regular Expression Search And Replace in Xcode Nick 4 4,301 Nov 25, 2006 03:47 PM
Last Post: Nick