Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux: C/C++ standard library static vs dynamic linking [duplicate]

Probably on any OS it is possible to compile C++/C standard library statically or dynamically. On Windows I prefer static builds always, because it helps to avoid "dll hell" problem with different versions of libraries installed or not installed on specific Windows version, edition and service pack, etc. Static linking makes software more portable and less dependent on what end user did with his operating system (I even saw examples when end user could make SHIFT+DEL on some DLLs in system32, he couldn't explain why, or when users claim that my app contains virus because it tried to download dynamically linked prerequisites from official Microsoft website...) So, on Windows static linking is usually better than dynamic one in my experience. However, I am new to Linux, so can anyone share his experience? My question is: what kind of linking (dynamic or static) is preffered on Linux if we ignore the fact that dynamic one allows to save memory & hard drive space and if we plan to distribute software with automated install program (hard drive space and memory are cheap enough now, so there are not reason to sacrifice hours of working time required to create really good and portable installer to win some megabytes of RAM or hard drive space). Are there any Linux-specific issues with dynamic/static linking?

like image 727
Vitalii Avatar asked Feb 19 '14 09:02

Vitalii


People also ask

Which is better static linking or dynamic linking?

Load time. Besides, static linking takes constant load time while dynamic linking takes less load time.

Is C standard library static or dynamic?

It's specific to the version of the compiler used. This library is always statically linked, even when using a dynamically linked UCRT.

Should I link statically or dynamically?

Dynamic linking has the following advantages over static linking: Multiple processes that load the same DLL at the same base address share a single copy of the DLL in physical memory. Doing this saves system memory and reduces swapping.

What is the difference between static library and dynamic library in Linux?

What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.


1 Answers

On Linux you normally have a package manager that ensures you only have one version of libraries installed. So there normally is no dll hell and no problem with linking dynamically. Linking dynamically is the standard way on Linux.

like image 191
TNA Avatar answered Oct 19 '22 23:10

TNA