How do I compile RHEL5 compatible shared library from RHEL6 machine with GCC 4.4.6?

606 views Asked by At

Note: I'am a C# Windows developer just entering the C++/Linux world.

I have a BOOST based cross platform C++ code which I need to compile as a shared library for:

  • Windows
  • RHEL6
  • RHEL5 and
  • Solaris

I have Windows and RHEL6 machines and have successfully built for those. Solaris build currently is not important.

According to this: Can I use a shared library compiled on Ubuntu on a Redhat Linux machine?

My RHEL6 compiled shared library won't run on RHEL5, because the following command:

readelf -s /path/to/your/library.so | egrep 'GLIBC_2.([6-9]|10)'

returns GLIBC2.7 dependency:

143: 00000000 0 FUNC GLOBAL DEFAULT UND eventfd@GLIBC_2.7 (14)
9069: 00000000 0 FUNC GLOBAL DEFAULT UND eventfd@@GLIBC_2.7

I was wondering if there is a way to build for RHEL5 through the RHEL6 machine? Or any other proposal will do. Thanks.

1

There are 1 answers

2
Maxim Egorushkin On BEST ANSWER

You can link your shared library with -Wl,-rpath,'$ORIGIN' and provide all the required libraries in the same directory.

However, if there is anything in your library headers that use any types from the C++ standard library, you are asking for troubles. The users of your library would have to build and link their applications using the same C++ compiler and the standard library.

The most portable option is to provide a shared library with C API along with C++ header-only wrappers, which users can build using any C++ compiler.