Reputation: 15121
When we create a static library, we have to provide clients with 2 files:
However, when we create a dynamic library, we must provide clients with 3 files:
As far as I know, I cannot build a client app (such as a console app) that
When I build a simple console app as follows, for example:
#include <iostream>
int main()
{
std::cout << "Hello World!";
return 0;
}
The output (.exe file in this case) is self-contained. Does it mean that "all c++ standard libraries are static libraries" ?
Upvotes: 1
Views: 1904
Reputation: 25418
On Windows, when building with Visual Studio at least, you can choose whether to link against the static (.lib) or dynamic (.dll) runtime libraries. You select this in the project settings somewhere.
The former makes your .exe more portable as it doesn't rely on the DLLs for the version of the runtime library you linked against being present on the target machine. It is therefore my personal preference. The latter makes your program smaller.
Upvotes: 2
Reputation: 206747
The output (.exe file in this case) is self-contained. Does it mean that "all c++ standard libraries are static libraries" ?
No. No.
When I execute ldd
on a simple C++ program in Linux, I get.
linux-vdso.so.1 => (0x00007ffc125f2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6e371b2000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6e3757c000)
That means, the executable will not run unless you have those dynamic libraries.
You will find similar dependencies on Windows.
Upvotes: 3