Errors of libstdc ++ GLIBCXX version

when I compile a C ++ program on my computer using g ++ and transfer the executable to run it on my university server, I get

./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by ./main) ./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by ./main) ./main: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not found (required by ./main) 

The program works well on my computer, and I do not have privileges to install any new software on my university servers.

any help? Thanks

+7
source share
4 answers

It seems you are using the standard library as a shared library (default behavior) when linking your program at home.

Therefore, instead of really “linking” the library, your linker simply solves some characters and performs another operation, delaying the actual loading of the library at runtime.

When you run your program on your university computer, the loader (the program that actually loads your program into memory and throws the main thread) looks for the libraries that your program needs and tries to load them (see LD_LIBRARY_PATH on Linux if you're interested).

The problem is that you are linking your program at home with a version of stdlib, which is not the same version as your university. Therefore, when the bootloader tries to find the library, it fails, and therefore your program cannot be started.

Solutions:

a) To avoid all these problems, use static linking instead of dynamic linking. I'm not sure if this is possible with stdlib, but I think it's worth checking it out (see http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html and look for "- a static flag)

b) You can try to compile your program on your university computer so that it uses the version there.

c) Try to find out which version of stdlib is installed there and install the same version on your compiler.

d) You can try to copy the home version of stdlib to the same folder as your application. This usually works because the bootloader tends to search for shared libraries in the current application folder before searching in the path specified in the environment variable LD_LIBRARY_PATH (linux)

Hope this helps.

PS: Here you have a good introduction to static vs shared / dynamic libraries http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html

And here ( http://en.wikipedia.org/wiki/Library_%28computing%29 ) is not a very pleasant, but more complete description of the library.

+7
source

The libstdc++.so.6 too outdated on the university computer. You have two options:

  • Static link with -static . Then the C ++ library will be combined with the final binary.
  • Copy the correct version somewhere in your home directory and then specify it either by passing -rpath /path/to/library/directory at build time or by setting the LD_LIBRARY_PATH environment LD_LIBRARY_PATH to point to the directory containing the new libstdc++.so.6 .
+5
source

You can copy your version of /usr/lib/libstdc++.so.6 to a subdirectory of your server’s home directory, say ~/lib , and then run:

 $ LD_LIBRARY_PATH=$HOME/lib ./main 

Or if you prefer

 $ export LD_LIBRARY_PATH=$HOME/lib $ ./main 

And the program should load your personal library instead of the system one.

+3
source

What platforms are you trying to compile on? "Your computer" and "University servers"?

You can try compiling your program with a static link. This will create a statically linked executable with all lib dependencies already loaded.

Greetings

+1
source

All Articles