Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Question about dynamic and static libraries
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about dynamic and static libraries



On 28/12/2005, at 8:59 PM, Eric Albert wrote:
Also, I'm noting a weird behavior. When I build my app, it will link
to the .dylib unless I delete the libraries from /usr/local/lib and
copy the .a file into my project. In that case, otool does not show a
dependency on the .dylib. However, if I run the app on a machine where
these files exist in /usr/local/lib, it will use the version of the
library from that directory. Why does this happen? How can I avoid
this? I want it to always use my static library.

The easiest thing to do is to not build the dynamic library version at
all. You can often do that with configure scripts by running
'./configure --disabled-shared'. Oh, and delete the /usr/local/lib bit
first. :)

This is not weird behaviour. There are very good reasons for he behaviour.


MacOS X ships with multiple compiler versions. You may well have gcc 2.95, gcc 3.x and gcc 4.x all installed. Dynamic libraries are compiler independent. Static libraries, which are just object code archives, are not compiler independent. You see plenty of problems on these lists from people trying to link code from a static library built with gcc 3 with some other objects built with gcc 4 and vice versa. Linux distros tend to have a system compiler which was used to build the system itself and all enhancements. so this issue is less common.

For this and other good reasons, the use of static libraries is deprecated on MacOS X. So the linker ld will always use a dynamic library if it can find one on the search path.

If the library is useful in more than one project, make it dynamic. If not, build it in the source tree of the project and don't install it.

Bill Northcott

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.