Search code examples
c++linuxeclipsebinaryfiles

Distribute C++ binaries across linux


I would like to distribute C++ binary that is created by using Eclipse ++ IDE, with the following settings:

Cross GCC Compiler: gcc -std=c++17 
Cross G++ Compiler: g++ -std=c++17
Tool Chain settings:
Cross GCC Compiler
Cross G++ Compiler
Cross GCC Linker
Cross G++ Linker
Cross GCC Archiver
Cross GCC Assembler

I am compiling with boost::serilization and have connect that in Linker. The binary is created on Ubuntu 16.04. I tried to run the binary on Ubuntu 14.04, and it give the error:

error while loading shared libraries: libboost_serialization.so.1.58.0: cannot open shared object file: No such file or directory.

I have also installed libboost on the system by using

sudo apt-get install libboost-program-options-dev

But, it gives me the same error.

I think with the above Eclipse IDE setting, it should work in most of the Linux platforms. Is my presumption of its working on most of the Linux platforms wrong??.


Solution

  • When you build your program you link it with specific versions of the shared libraries. On older releases of e.g. Ubuntu those newer versions of the libraries doesn't exist.

    If you want to copy the executable between different systems you need to link statically. That means all libraries are linked into the executable so it doesn't rely on shared libraries. It will make the executable bigger of course.