Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libstdc++ GLIBCXX version errors

Tags:

c++

g++

libstdc++

when I compile a c++ program in 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 runs well on my computer, and I don't have privileges to install any new software on my university servers.

any help ? Thanks

like image 445
Tarek Avatar asked Aug 22 '11 16:08

Tarek


4 Answers

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

So rather than really "linking" the library, your linker just resolves some symbols and does another operation, while delaying the actual loading of the library to run-time.

When you execute your program at your university computer, the loader (the program which actually loads your program in memory and throws the main thread) looks for the libraries your program needs and tries to load them (look for LD_LIBRARY_PATH in linux if you feel curious).

The problem here is that you are linking your program at home with a version of the stdlib that is not the same version as what you have at the university. So when the loader tries to find the library, it fails, and so your program cannot be run.

Solutions:

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

b) You can try to compile your program at your university computer so it will use the version there.

c) Try to know which stdlib version is installed there and install the same version in your compiler machine.

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

Hope that helps.

P.S.: Here you have a nice 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) a not so nice but more complete library description.

like image 192
thamurath Avatar answered Oct 06 '22 00:10

thamurath


The version of libstdc++.so.6 is too old on the university computer. You have two options:

  1. Statically link with -static. The C++ library will then be merged into the final binary.
  2. Copy the correct version to somewhere in your home directory, then reference it either by passing -rpath /path/to/library/directory at build time, or setting the LD_LIBRARY_PATH environment variable to point to the directory containing the newer libstdc++.so.6.
like image 44
bdonlan Avatar answered Oct 06 '22 00:10

bdonlan


You can copy your version of the /usr/lib/libstdc++.so.6 to a subdirectory of your home directory of the server, 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 private library instead of the system one.

like image 44
rodrigo Avatar answered Oct 06 '22 00:10

rodrigo


What platforms are you trying to compile for? i.e. 'Your computer' and your 'University servers' ?

You could try compiling your program with the static linking option. This will generate a statically linked executable with all lib dependencies loaded already.

Cheers,

like image 33
quarkonium Avatar answered Oct 06 '22 01:10

quarkonium