What is the Difference Between Dynamic and Static Files
Product: ShopSite SC + TX
Platform: Any UNIX Platform (including Cobalt RAQ)
Often there is mention of static versus dynamic versions of a ShopSite CGI executable file. What is the difference?
Solution ID: S04240
Every UNIX program/executable can be thought of as static or dynamically compiled, or static and dynamically built. When a UNIX program is static, all the necessary libraries required for that program to run are built into the executable. When a UNIX program is dynamic, all the necessary libraries required for that program to run are located on the UNIX file system. In the case of dynamic programs, the UNIX libraries are considered "shared libraries" or "objects", and are often located in /usr/lib.
Static UNIX programs have the advantage that there are no dependencies on existing operating system libraries. However, they have a larger file size (as all the necessary libraries are stored within it).
Dynamic UNIX programs have the advantage that they have a smaller file size. However, if the shared library is not present on the UNIX file system, or the shared library is present, but not the right version, the dynamic UNIX program won't run.
On the UNIX command line, you can determine whether any executable file is built with static or dynamic libraries.
Use this command: file .
% file payconfig.cgi
payconfig.cgi: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
Notice how the output states it's dynamically linked. This is not static. Another example:
% file sync
sync: ELF 32-bit MSB executable SPARC Version 1, statically linked, stripped
Notice how it says that it's statically linked.
You can determine what libraries a UNIX program is looking for when it runs. Use the ldd command:
% ldd payconfig.cgi
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
libdl.so.1 => /usr/lib/libdl.so.1
No related articles were found.
No attachments were found.