Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newbie xcode linker question

79 views
Skip to first unread message

mlabs

unread,
Feb 6, 2008, 12:37:24 AM2/6/08
to
I'm trying to create a new framework. The source files need use
libxml2, which comes with the 10.5 sdk.
I added this to the header search paths:
/Developer/SDKs/MacOSX10.5.sdk/usr/include/libxml2
and got it to compile.

Next I drag-dropped libxml2.dylib into my xcode project under
'External Frameworks and Libraries' .. and also under 'Link Binary
With Libraries' just for good measure... no idea why I should specify
the link dependencies in two places but whatever...

I still get linker errors. So I looked at the build transcript and in
particular noticed that libxml2.dylib wasn't mentioned on the Ld
command-line ... even though it is referenced explicitly in the xcode
project...

Q: Shouldn't drag-dropping that dylib into the project GUI like that
be telling the linker 'hey i want to link with this dylib' ?
If not, what's the best way to link with external dylibs?

TIA

mlabs

unread,
Feb 6, 2008, 2:34:30 AM2/6/08
to
I found that if in addition to having the refs to libxml2.2dylib in
the GUI, if I also used '-l xml2.2' in the 'Other LInker Flags'
section AND the path to the SDKs 'usr/lib' directory, it would link.
I don't know what is going on... can anybody explain?

for example, why '-l xml2.2' and not '-l libxml2.2' ?
why doesn't xcode pass the path to the file i drag-dropped to the
linker..? 'get info' seems to know where the thing is....
are these just bugs?

Patrick Machielse

unread,
Feb 6, 2008, 5:20:42 AM2/6/08
to
mlabs <aaron.mir...@gmail.com> wrote:

> I'm trying to create a new framework. The source files need use
> libxml2, which comes with the 10.5 sdk.
> I added this to the header search paths:
> /Developer/SDKs/MacOSX10.5.sdk/usr/include/libxml2
> and got it to compile.
>
> Next I drag-dropped libxml2.dylib into my xcode project under
> 'External Frameworks and Libraries' .. and also under 'Link Binary
> With Libraries' just for good measure... no idea why I should specify
> the link dependencies in two places but whatever...
>

> Q: Shouldn't drag-dropping that dylib into the project GUI like that
> be telling the linker 'hey i want to link with this dylib' ?
> If not, what's the best way to link with external dylibs?

Hi,

You must deal with two issues here: how the compiler and the linker find
headers and libraries, and how Xcode uses SDKs. These two settings
interact, so be careful when changing settings.

libxml is shipped in both 10.4 and 10.5. In your code, you should
include the headers like so:

#include <libxml/someheader.h>

The angle brackets denote a library, and ensure that the a number of
standard locations is searched for someheader.h (this probably includes
usr/include/libxml2, so you wouldn't need to add any custom search path
to the build settings).

To instruct ld to link against a library called 'libName' you specify
the linker flag '-lName'. That's the rule. To link against libxml2.dylyb
you would pass '-lxml2'. If you look in /usr/lib (on 10.5) you'll see
that this is acutally a symlink to the currently shipped version
libxml2.2.dylib. I believe that setting a linker flag in the build
settings and adding a library to the target's 'Link Binary With
Libraries' section amount to the same thing.

Note that all locations above are spcified from the root, and you should
not point to a path inside an SDK yourself. Instead, Xcode will
automatically prepend the search paths with the SDKROOT build setting.
This way, you can target a different OS version by changing just one (or
a handful) of settings.

I hope this gives you a (very short!) handle on linking and libraries,
but you probably want to read up on the documentation, or this will keep
coming back to hount you. I promise ;-)

patrick

mlabs

unread,
Feb 6, 2008, 6:18:19 AM2/6/08
to
thanks -
since posting, i have found the documenataion on ld that says -lfoo
will look for libfoo.a .. how dumb is that .. lol
as for the xcode GUI - I think it is just buggy. There really should
not be a need to specify -lfoo in 'Othe LInker Options' *after*
dragging a ref to the dylib into the 'link binary with libraries'
section of the target .. that's pointless.. it has to be a bug ...
it's two ways of doing the same thing ...xcode should be able to
generate the correct ld -l from what i drag-dropped into that
section...


Patrick Machielse

unread,
Feb 6, 2008, 7:10:22 AM2/6/08
to
mlabs <aaron.mir...@gmail.com> wrote:

> as for the xcode GUI - I think it is just buggy. There really should
> not be a need to specify -lfoo in 'Othe LInker Options' *after*
> dragging a ref to the dylib into the 'link binary with libraries'
> section of the target .. that's pointless.. it has to be a bug ...
> it's two ways of doing the same thing ...xcode should be able to
> generate the correct ld -l from what i drag-dropped into that
> section...

Make sure you add /usr/lib/libxml2.dylib, and not the dylib from one of
the SDKs. That should work. In general, if you add Mac OS X frameworks
to your project, choose the ones in /System/Library/Frameworks. At build
time the correct SDK version will be used.

patrick

0 new messages