Conclusion of C ++ Libraries
I read about how to compile a makefile, but no one seems to mention what to do if your files require different sets of libraries, they all seem to use the same set of libraries for each file. Since it seems unlikely that every file has the same libraries, I take a list of them that they use should combine all the libraries needed for the project.
I just wanted to know if there is a downside to include too many libraries, or if the compiler develops which ones are needed and ignores the rest?
thanks
a source to share
If there are any drawbacks to include too many libraries?
Hardly anyone.
If the compiler develops which ones are needed and ignores the rest?
Almost exactly: it's a linker that parses each library and extracts only the object code it needs.
The only drawback is the inclusion of a large number of libraries in that it will be difficult to get them in the correct order. Recent versions of the GNU linker have some special options that can help with library problems - out of order (and about time), but such options remain non-portable. On the other hand, if you include libraries that you don't really need, it doesn't matter in what order they appear, because the linker will scrutinize each one carefully and decide that none of its content is required.
For all those people looking for projects, here I would like to: give me a tool that takes a list of libraries and does a topological sort for interlibrary dependencies, and then tells me the order I can put them on the command line, so there is no free undefined symbols.
a source to share
A component (a tool that takes all files .o
created when compiling source code and turns them into an executable file) will not link to code that has not been called into an executable file. That is, simply stated:
void foo()
{
// code
}
void bar()
{
// code
}
int main()
{
foo();
return 0;
}
Here, the code foo
will be linked to the executable and the code bar
will not. Assuming that's the whole program, of course.
For a more complete explanation, read the answer I gave just an hour ago to another question.
a source to share