Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't a C++ static library project have linker settings?

Revealing my ignorance: Why doesn't a static library project (in Visual Studio in my case) have linker settings in the project properties page? I thought "linking" was kind of a big deal re: libraries, but apparently I fundamentally misunderstand something.

like image 639
vargonian Avatar asked Jun 25 '11 06:06

vargonian


3 Answers

Making an executable is a three step process:

  1. A compiler transforms source code in to object files.
  2. An archiver/librarian groups the object files together into libraries (this step is optional).
  3. A linker links the object files and libraries together to create a complete executable.

A library is just a collection of objects, which by definition have not been linked yet. The linker is not used to create the library, so it makes sense that there would be no linker options for it.

like image 179
David Grayson Avatar answered Nov 15 '22 23:11

David Grayson


Linking is a process of combining object files into executables (and dynamic libraries, which have similar to executables format).

Static libraries aren't linked, they are simple archives of object files.

When you reference static library in your project, object files are extracted from library and linked together with files of particular project.

like image 41
elder_george Avatar answered Nov 16 '22 00:11

elder_george


Because you don't link it, pure and simple.

Linking is the act of pulling together all your object files and libraries to create an executable. In a static library project you're not making an executable, you're just creating a library which will later be linked.

For example (and this is UNIX rather than Windows, but the concepts are similar), you would use the compiler cc to turn your source files into object files and the archiver ar to turn those into a library. The linker (or linkage editor) ld does not need to take part until you wanted to go to the next step and include your library into an executable.

like image 44
paxdiablo Avatar answered Nov 16 '22 00:11

paxdiablo