Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Linking/Loading/Libraries...

Linking/Loading/Libraries...
Thread Tools
Mac Enthusiast
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jun 2, 2001, 02:49 PM
 
Hi,

I'm new to UNIX-programming but have some experience with the classic environment. Right now I'm trying to build an interpreter and I'd like to use existing (C-)libraries to save work. I played with cc, as and ld, but I'm confused with all these libraries in /usr/lib and things like dynamic linking/static linking. I couldn't find good reference on these topics, so if anybody knows a good link or can explain to me the depths of compiling, linking, loading, executing, libraries etc, this would be a great help to me.

-- Daniel
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jun 5, 2001, 08:11 AM
 
First, as opposed to messing with makefiles and the like, I'd recommend that you just use Project Builder and not cc, ld, etc directly. It makes it much simpler.

Anyway, static linking is probably what you are used to. It basically means that when your program is linked, it knows exactly where to look for things. For example, if you write a function in C and call it, then that function will be statically compiled into your program. The resulting code will know exactly where to branch to do that function. In contrast, with dynamic linking, the linker may not know where lots of stuff is and the location of that stuff is not determined until runtime. Although dynamicly linked programs are slower than statically linked ones (there is overhead of linking stuff while it is running) they have a number of advantages.

If I write something in Objective C, for example, pretty much everything is dynamically linked. So, If I call some method in NSImage, it will be determined at runtime, where to look for that method. The advantage of this is suppose that there are some horrid bugs in a library, or a library is inefficient. If it it dynamically linked, then Apple can update the library and WITHOUT recompiling, the program that dynamically links against those libraries gets the benefits of the updated code. If everything was statically linked then the programmer would have to recompile his program against the new libraries and release a new version.

So: dynamic linking is slower, but if the libraries that a program links against get updated, then the program kind of gets updated too, with no help from the developer. Statically linked stuff is faster, but if a library changes the developer needs to recompile and release a new version in order for the customer to get the benefits. Statically linked stuff may also be larger because, suppose that person A statically links a math library into his code, and person B dynamically links against a math library. All else equal, person A will have faster code, but it will take up more disk space because he has the whole math library compiled into his program.

Hope that clears up the static vs dynamic linking problem.
     
Mac Enthusiast
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jun 5, 2001, 09:27 AM
 
Hey Dalgo, thank you very much for your extensive answer! Now it's much more clear to me. The arguments point at dynamic linking, sounds more modern, so I will try to get some information about that.

-- Daniel
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2