Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static libraries, dynamic libraries, DLLs, entry points, headers ... how to get out of this alive?

I recently had to program C++ under Windows for an University project, and I'm pretty confused about static and dynamic libraries system, what the compiler needs, what the linker needs, how to build a library ... is there any good document about this out there? I'm pretty confused about the *nix library system as well (so, dylibs, the ar tool, how to compile them ...), can you point a review document about the current library techniques on the various architectures?

Note: due to my poor knowledge this message could contain wrong concepts, feel free to edit it.

Thank you

Feel free to add more reference, I will add them to the summary.


References

Since most of you posted *nix or Windows specific references I will summarize here the best ones, I will mark as accepted answer the Wikipedia one, because is a good start point (and has references inside too) to get introduced to this stuff.

Program Library Howto (Unix)

Dynamic-Link Libraries (from MSDN) (Windows)

DLL Information (StackOverflow) (Windows)

Programming in C (Unix)

An Overview of Compiling and Linking (Windows)

like image 224
tunnuz Avatar asked Apr 24 '09 06:04

tunnuz


People also ask

Can a DLL link to static library?

The DLL can link to the same MFC static link libraries used by applications. There is no longer a separate version of the static link libraries for DLLs.

Is DLL static or dynamic?

They are called dynamic because they are not embedded in the executable -- they just link to it when needed. An import library, which is a type of static library, replaces all placeholder symbols with actual links to the necessary DLL data in the main program at load time, pulling those functions from the DLL library.

What is the difference between static library and DLL?

A static library must be linked into the final executable; it becomes part of the executable and follows it wherever it goes. A dynamic library is loaded every time the executable is executed and remains separate from the executable as a DLL file.

How are dynamic libraries linked?

Dynamic libraries are linked during the execution of the final executable. Only the name of the dynamic library is placed in the final executable. The actual linking happens during runtime, when both executable and library are placed in the main memory.


2 Answers

Start with Wikipedia - plenty of information there, and lots of links to other useful resources.

P.S. But perhaps it would be better to just ask a specific question about the problem you're currently having. Learning how to solve it may go a long way to teaching you the general concepts.

like image 62
Eli Bendersky Avatar answered Oct 11 '22 12:10

Eli Bendersky


You can find some background information from this article here. It gives you the basic background. I'm trying to locate something with diagrams. This should be a good place to get started.

The fundamental differences between a static library and a DLL is that with the static library the code is compiled into your final executable whereas a dynamic link library involves linking in a "stub" library (into your application) which contains mappings to functions in a separate file (.dll).

Here's an MSDN entry on creating a static Win32 Library which might also help you. ..another link to MSDN for creating a Dynamic Link Library..

Just found this site which covers definitions of basically all the aspect you've quoted.

like image 26
RobS Avatar answered Oct 11 '22 12:10

RobS