7

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

phoxis
  • 60,131
  • 14
  • 81
  • 117
Tarek
  • 1,060
  • 4
  • 17
  • 38

4 Answers4

8

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.

Trapsilo Bumi
  • 910
  • 8
  • 11
thamurath
  • 765
  • 8
  • 24
4

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.
bdonlan
  • 224,562
  • 31
  • 268
  • 324
  • many thanks bdonian, does the static linking make the program runs slower when executed in the university servers? – Tarek Aug 22 '11 at 16:37
  • @Tarek, static linking has various pros and cons, but I don't think you'll see much of a speed difference, really. – bdonlan Aug 22 '11 at 17:50
  • as @bdonian said there are many pros and cons, but in your case the main one will be the size. A statically linked program is bigger than the dynamically linked one because in the static-linked one the libraries are "included" inside the executable. – thamurath Sep 25 '11 at 15:42
  • 1
    A better option than `-static` would be `-static-libstdc++` which only links libstdc++ statically, not the entire program. – Jonathan Wakely Feb 11 '16 at 13:03
4

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.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
1

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,

quarkonium
  • 128
  • 6