问题描述
当我在我的计算机上使用 g++ 编译一个 c++ 程序并传输可执行文件以在我的大学服务器上运行它时,我得到了
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.
有什么帮助吗?谢谢
推荐答案
在家中链接程序时,您似乎正在使用标准库作为共享库(默认行为).
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.
当您在大学计算机上执行程序时,加载程序(实际将您的程序加载到内存中并抛出主线程的程序)会查找您的程序需要的库并尝试加载它们(查找 LD_LIBRARY_PATH
如果您感到好奇,请在 linux 中使用).
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).
这里的问题是,您将在家中使用的 stdlib 版本与您在大学中使用的版本不同的版本链接您的程序.所以当加载器试图找到库时,它会失败,所以你的程序无法运行.
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.
解决方案:
a) 为避免所有这些问题,请使用静态链接而不是动态链接.我不确定这是否可以使用 stdlib,但我认为值得对其进行测试(参见:http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html 并寻找-static"标志)
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) 您可以尝试在您的大学计算机上编译您的程序,以便它使用那里的版本.
b) You can try to compile your program at your university computer so it will use the version there.
c) 尝试知道那里安装了哪个 stdlib 版本,并在您的编译器机器中安装相同的版本.
c) Try to know which stdlib version is installed there and install the same version in your compiler machine.
d) 您可以尝试将您的家庭版本的 stdlib 复制到您的应用程序所在的同一文件夹中.这通常有效,因为加载程序倾向于在当前应用程序文件夹中搜索共享库,然后再查看环境变量 LD_LIBRARY_PATH
(linux)
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)
希望对您有所帮助.
附:在这里,您可以很好地介绍静态库与共享/动态库 http://www.network-theory.co.uk/docs/gccintro/gccintro_25.html
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
这里(http://en.wikipedia.org/wiki/Library_%28computing%29) 不是很好但更完整的库描述.
And here (http://en.wikipedia.org/wiki/Library_%28computing%29) a not so nice but more complete library description.
这篇关于libstdc++ GLIBCXX 版本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!