Will the copied executable run on a new machine without libraries

If I compile a C ++ program in a Linux box where many libraries are installed (for example, Boost), and then copy this executable file to a new Linux module without these libraries, will the executable work fine?

+4
source share
2 answers

It depends on the specific libraries. There are three types of libraries:

  • Libraries for headers only - these dependencies are resolved at compile time.
  • Static libraries - these dependencies are resolved during the connection.
  • General (dynamic) libraries - these dependencies are resolved at runtime.

In most Boost libraries, header-only : when linking, they do not require separately compiled libraries or special handling. Other libraries are static, i.e. They are only needed during assembly for assembly. The only libraries that should be available on the target machine are dynamic (shared) libraries; if you do not have dynamic library dependencies, copying the executable file and setting the appropriate permissions will work fine.

+3
source

Libraries can be either statically linked (in this case they are copied to the executable file) or linked dynamically (in this case they are loaded by the system from their own copy at runtime)

Almost all libraries will be dynamic - it allows you to use only one copy of the code for many programs and means that you can only update one file to fix the error.

0
source

All Articles