Question

The code is written in c/c++,may depend some libs in the compiling host; and it should run in another host without libs depending problems. Both hosts are linux, may have different versions. Do you have a good strategy?

Was it helpful?

Solution

Pure static linking on Linux is discouraged, it's only really possible if you use an alternative libc (such as dietlibc) which isn't an option with C++, my favoured approach is to build the application on the oldest version of Linux you have to support as the newer libc builds will have backwards compatibility.

This will only cover libc, other requirements, such as gtk, pangom, etc will have to be compiled directly into your binary.

OTHER TIPS

Link the application statically, so that it depends on as few dynamically loaded libraries as possible. This is the general solution to this problem.

Other solutions include:

  • Ship the required libraries with the application, and override the system's LD_LIBRARY_PATH variable to make the included versions the preferred ones.
  • Write code to dynamically load the libraries using dlopen() and friends, and handle differences in library versions manually.

Most platforms have a well-defined ABI that covers C code, but ABIs that cover C++ functionality are not yet common.

A program written in c++ using just libc may not run on another platform. if binary compatibility is an important issue consider using c.

Take all answers for this question into account (static linking, compiling on the oldest Linux, etc.) and then check your final binary by the Linux App Checker to show compatibility issues with other Linux distributions.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top