2

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?

shenyan
  • 408
  • 4
  • 9

4 Answers4

3

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.

Community
  • 1
  • 1
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
2

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.
unwind
  • 391,730
  • 64
  • 469
  • 606
0

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.

arash kordi
  • 2,470
  • 1
  • 22
  • 24
  • why do you think a c++ library can not preserve binary compatibility, and c can? – BЈовић Oct 09 '12 at 11:20
  • for C++ there are 3 major categories : Itanium C++ ABI, Microsoft ABI and others. you simply can't link against a library with a different ABI than yours. and from my own experience a simple "hello world" executable written on a standard fedora 14 distribution produced "seg fault" on a "debian lenny" (I don't rememer library versions!!) – arash kordi Oct 09 '12 at 11:44
0

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

linuxbuild
  • 15,843
  • 6
  • 60
  • 87