Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: linking in static libraries under xcode?



From: Ken Hawkins <email@hidden>
Subject: linking in static libraries under xcode?
Date: Wed, 4 Feb 2004 10:19:29 -0800

i have 2 static libs that are built in the same project libx and liby.
however i cannot get link them into my BSD shell target "reader".

i see under the info where i can call out the library style as static
however i cannot see where i can put in the -lx -ly args in to the
build. i tried under other linker flags however this did not work. can
anyone help out here?

I futzed around with something like this recently.

As far as I can see Apple expects all object files in one project to be linked in at once, not as is often done with makefile projects where objects are archived into 'static' libraries and then those are given as arguments to ld.

As far as I could see -lfoo does not work with Apple ld if libfoo.a is a Linux style archive made with ar. ld can produce 'static' libraries with the -static flag and as far as I know these should be linkable as long as they are ranlibbed first, but I have not tried this.

Basically as I understand the Xcode way of doing it, you designate all the source files and let Xcode do the rest.

The solution to our problem was to stick with GNU libtool. (Our project is built with GNU libtool not the Xcode build system) The libfoo.a I was trying to link was a libtool library (ie an archive made with ar). So there was a libfoo.la. I stuck that onto the libtool invocation as a file reference and and it worked. ie
libtool mode=link ......... libfoo.la

An alternative, if you have to use ld, is to put on the link line libfoo.a/foo.o libfoo.a/bar.o and so on for each object in the archive you want to link. That is actually what GNU libtool does.

Bill Northcott

PS It was a good learning exercise but a waste of time because when I finally got it linked the resulting executable crashed in one of the library functions:-(
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.