mlabs 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
>> Stay informed about: newbie xcode linker question