Jinoh  Kim
Jinoh Kim

Reputation: 45

Who determine GLIBCXX_version when build a binary using g++?

I am building an self-made shared library using G++ 4.9.3 on Centos 6.8.

This library uses boost::interprocess::file_lock and version of boost is 1.41.0.

I am not working on multiple environment.. I just use a device and I've never changed build environment after I built the library.

When I build library, g++ build it well. But when I run it by linking with an binary, it shows "./a.out: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./libmylib.so)".

So, I checked which versions supported by the libstdc++ and it show it doesn't support GLIBCXX upper than 3.4.13. GLIBCXX_3.4.13 is the latest version of /usr/lib64/libstdc++.so.6 supports.

Even though I am working on a device and its libstdc++ doesn't support GLIBCXX_3.4.15, the library build from my device requires GLIBCXX_3.4.15.

And another binaries doesn't require GLIBCXX_3.4.15 even if I use same compiler(g++4.9.3). They just work well.

How can the library notice it should use GLIBCXX_3.4.15?

Is it differed by source code?

Does compiler tell the library such as "you require to use GLIBCXX_3.4.15 because you use some special grammar in your code"?

I want know who determine which version of GLIBCXX to use for a binary.

Upvotes: 2

Views: 181

Answers (1)

Florian Weimer
Florian Weimer

Reputation: 33717

It depends on the version of GCC, the compiler flags, and the source code. Symbols such as GLIBCXX_3.4.15 are only referenced if a specific feature is used in a program. The list of features for this particular symbol version is rather large. You can get a sense of what features are relevant using this command (which you have to run against the newer libstdc++, i.e. the one that comes with GCC 4.9):

$ readelf -sW libstdc++.so.6 | awk '/@GLIBCXX_3.4.15/{print $8}' \
  | sort -u \
  | c++filt

If you want to run your program with the unmodified libstdc++.so.6 version that comes with Red Hat Enterprise Linux or CentOS, you can use Developer Toolset (which is also available as a supported part of Red Hat Enterprise Linux. Developer Toolset avoids dependencies on newer symbol versions by using the old (C++98 era) C++ ABI and providing statically linked copies of functions which are not part of the system libstdc++ version for the particular target operating system version.

Upvotes: 1

Related Questions