Interesting question. Hadn't really thought of it like that. If someone wants to do the following in VSC++ or with other libs to compare that would be cool. Using gcc/g++ and SDL2 on Linux this what I got;
By taking the following code:
using namespace std;
cout << "hello\n";
I ran these tests;
noLibs: default, no linking, no headers
SDLLinked: Linked to the SDL2 library, but did not #include <SDL2.h> in the code
SDLHeaderLinked: Added a single #include to the SDL2 library and also linked in make
SDLHeaderLinkedInitialized: did all the above and called SDL_INIT(SDL_INIT_EVERYTHING);
|19936(bytes) Nov 7 19:19 noLibs |
19936(bytes) Nov 7 19:19 SDLLinked
19936(bytes) Nov 7 19:19 SDLHeaderLinked
19976(bytes) Nov 7 19:19 SDLHeaderLinkedInitialized
// same as above 3 but with -O3 turned on:
19832(bytes) Nov 7 19:19 noLibsOptimized
19832(bytes) Nov 7 19:19 SDLLinkedOptimized
19840(bytes) Nov 7 19:19 SDLHeaderLinkedOptimized
19880(bytes) Nov 7 19:19 SDLHeaderLinkedInitializedOptimized
So adding linkage and including the library headers has pretty much no effect in g++ (though oddly it did by 8 bytes with Optimization turned on). It took actually calling a function from the library before it changed the size of the output file.
I'll note that removing the #include <iostream> does change the size of the output file by some 700 bytes or so. If C++ native libs follow different rules, maybe other external libs might as well? SDL is pure C, so maybe libs containing C++ template classes might make a difference (that could modify the vtable, though I don't think it would until said template class/function was actually used. I can't think of any libs that use template classes/functions to test this on...)
Upside: you don't have to type several repetitive lines of code every time you start a new project.
Downsides might include people thinking they have to learn those included libs in order to work on your code, general confusion, and added lines of code for no reason. If the linkage is made as well then you have to work out shared dll/so files or just remember to fix the Makelist before distributing. In general the downsides are only relevant if you intend to share your programs with other people...