开发者

libstdc++ GLIBCXX version errors

开发者 https://www.devze.com 2023-03-30 09:46 出处:网络
when I compile a c++ program in my computer using g++ and transfer the executable to run it on my university server, I get

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++.开发者_StackOverflow中文版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


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.


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.


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.


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,

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号