If I compile a C++ program on a linux box that has many libraries installed (Boost for example) and then copy that executable to a new linux box without those libraries, will the executable still run properly?
-
It doesn't matter what libraries were installed on the build system, it matters what libraries were linked to and whether they were statically or dynamically linked. – Vaughn Cato Feb 04 '13 at 04:08
2 Answers
This depends a lot on the specific libraries. There are three kinds of libraries out there:
- Header-only libraries - these dependencies are resolved at compile time.
- Static libraries - these dependencies are resolved at link time.
- Shared (dynamic) libraries - these dependencies are resolved at run time.
Most Boost libraries are header-only: they require no separately-compiled library binaries or special treatment when linking. Other libraries are static, i.e. they are needed only at build time for linking. The only libraries that must be available on the target machine are dynamic (shared) libraries; if you have no dynamic library dependencies, copying an executable and setting the appropriate permissions will work fine.

- 714,442
- 84
- 1,110
- 1,523
Libraries can either be statically linked (in which case they are copied into the executable) or dynamicaly linked (in which case they are loaded by the system from its own copy at run time)
Almost all libraries on will be dynamic - it allows only one copy of the code to be used by many programs and means you can update only a single file to fix a bug.

- 94,801
- 28
- 188
- 263