Welcome to MacBoardz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

newbie xcode linker question

 
   Macintosh computer (Home) -> Programmer Help RSS
Next:  How do I create a sound input device in my System..  
Author Message
mlabs

External


Since: Feb 05, 2008
Posts: 3



(Msg. 1) Posted: Tue Feb 05, 2008 9:37 pm
Post subject: newbie xcode linker question
Archived from groups: comp>sys>mac>programmer>help (more info?)

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

 >> Stay informed about: newbie xcode linker question 
Back to top
Login to vote
mlabs

External


Since: Feb 05, 2008
Posts: 3



(Msg. 2) Posted: Tue Feb 05, 2008 11:34 pm
Post subject: Re: newbie xcode linker question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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?

 >> Stay informed about: newbie xcode linker question 
Back to top
Login to vote
mlabs

External


Since: Feb 05, 2008
Posts: 3



(Msg. 3) Posted: Wed Feb 06, 2008 3:18 am
Post subject: Re: newbie xcode linker question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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...
 >> Stay informed about: newbie xcode linker question 
Back to top
Login to vote
noreply

External


Since: Dec 02, 2004
Posts: 191



(Msg. 4) Posted: Wed Feb 06, 2008 11:20 am
Post subject: Re: newbie xcode linker question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 Wink

patrick
 >> Stay informed about: newbie xcode linker question 
Back to top
Login to vote
noreply

External


Since: Dec 02, 2004
Posts: 191



(Msg. 5) Posted: Wed Feb 06, 2008 1:10 pm
Post subject: Re: newbie xcode linker question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

mlabs 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
 >> Stay informed about: newbie xcode linker question 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Xcode - no linker errors? - hi! Errors I am accustomed to getting at link time (!) are not happening with Xcode. I read a bit and I think I might be a "victim" of Zerolink. I could not find any way to turn on/off this feature. I did change the development 'style' to....

Xcode linker symbol polution with a Framework - I am building a plugin for a product with Xcode. In my code is a source file with some symbols in it, which I link with into my bundle. I also link with some Frameworks from the host application. One of those Frameworks also happens to have the same..

Undefined Symbol Xcode linker error with no symbol listed - I am getting an Undefined Symbol error at link time in Xcode with no undefined symbols listed. I don't know what to fix and I don't know where to start. The detailed compiler/linker window pane spit out the following but I don't know how to read it. ..

xcode linker error: Undefined symbols, but no symbols listed - I'm building a rather large application being ported from Windows to Mac (using Qt as a cross-platform UI framework). All of my code compiles, but when I get to the linker state, it bails with one error: <font color=purple> ; Undefined..

newbie xcode problem - OS X 10.3.2 hello, I am new to xcode (i usually use RB5.2 ) and i have created a new Cocoa application consisting of just a single brushed metal window. I have built the application, but there seems to be 1 small stupid problem that i cant figure..
   Macintosh computer (Home) -> Programmer Help All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]