d7d1cd
d7d1cd

Reputation: 307

Problem when porting a program compiled using a new compiler

On the CentOS 7.5 operating system, the gcc compiler version 13.3 was built from the source code. Using this compiler, the test program was built

g++ main.cc -std=c++20

After the build, the program runs and works correctly. Then the program was "handed over to the customer", where he tried to run it on the same operating system, but where the default compiler gcc version 4.8.5 was installed. As a result, the following errors were received:

/a.out: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /a.out)
/a.out: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by /a.out)
/a.out: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /a.out)
/a.out: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /a.out)

Is it possible to configure the new compiler so that the programs it builds are portable? After all, it somehow works when the compiler is installed from devtoolset-11 (the programs built there work on machines without this compiler).

Upvotes: -1

Views: 103

Answers (2)

Ahmed AEK
Ahmed AEK

Reputation: 18090

Solutions that worked for me

  1. If you are only shipping an executable with no shared libraries you can statically link libgcc and libstdc++ with -static-libgcc -static-libstdc++ (i actually do this in one of my projects linux releases)
  2. If you are also shipping shared libraries then you need to also ship libgcc.so and libstdc++.so and you need to add the folder containing them to the start of the LD_LIBRARY_PATH before starting the executable (a shell script can help with this, but you can create a C wrapper that does this, which i did in a commercial application i worked on before), you may also need to set -Wl,-rpath,$ORIGIN when compiling depending on what system you are targetting. (The priority order of them changed over the years)

Shipping libgcc may not be necessary depending on how old the target system is, you'll have to test it out.

Also beware that redistribution licensing restrictions of libstdc++ apply, so if this is a commercial application then you could use clang libc++ instead which has no license restrictions

Upvotes: 0

Jesper Juhl
Jesper Juhl

Reputation: 31458

Check out Red Hat Developer Toolset. It does what you want - let's you use a newer compiler than the default one and produce binaries that are compatible with the base system.

Upvotes: 1

Related Questions