libstdc++ GLIBCXX 版本错误
当我使用 g++ 在计算机中编译 c++ 程序并传输可执行文件以在我的大学服务器上运行它时,我得到
./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)
该程序在我的计算机上运行良好,并且我没有权限在我的大学服务器上安装任何新软件。
有什么帮助吗? 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在家里链接程序时,您似乎正在使用标准库作为共享库(默认行为)。
因此,链接器只是解析一些符号并执行另一个操作,而不是真正“链接”库,同时将库的实际加载延迟到运行时。
当您在大学计算机上执行程序时,加载程序(实际上将程序加载到内存中并引发主线程的程序)会查找程序所需的库并尝试加载它们(查找
LD_LIBRARY_PATH 在 Linux 中,如果你感到好奇的话)。
这里的问题是,您在家中将程序链接到的 stdlib 版本与您在大学中使用的版本不同。因此,当加载程序尝试查找库时,它会失败,因此您的程序无法运行。
解决方案:
a) 为了避免所有这些问题,请使用静态链接而不是动态链接。我不确定 stdlib 是否可以做到这一点,但我认为值得对其进行测试(请参阅: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html 并查找“-static”标志)
b) 您可以尝试在大学计算机上编译您的程序,以便它将使用那里的版本。
c) 尝试了解那里安装了哪个 stdlib 版本,并在您的编译器计算机中安装相同的版本。
d) 您可以尝试将您的家庭版本的 stdlib 复制到您的应用程序所在的同一文件夹中。这通常是有效的,因为加载程序倾向于在当前应用程序文件夹中搜索共享库,然后再查看环境变量 LD_LIBRARY_PATH 中设置的路径(linux)
希望有所帮助。
附:
在这里,您对静态库与共享/动态库进行了很好的介绍 http:// www.network-theory.co.uk/docs/gccintro/gccintro_25.html
这里(http://en.wikipedia.org/wiki/Library_%28computing%29) a不太好但更完整的库描述。
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.
大学计算机上的
libstdc++.so.6
版本太旧。您有两个选择:-static
进行静态链接。然后,C++ 库将合并到最终的二进制文件中。libstdc++.so.6
的目录。The version of
libstdc++.so.6
is too old on the university computer. You have two options:-static
. The C++ library will then be merged into the final binary.-rpath /path/to/library/directory
at build time, or setting theLD_LIBRARY_PATH
environment variable to point to the directory containing the newerlibstdc++.so.6
.您可以将
/usr/lib/libstdc++.so.6
版本复制到服务器主目录的子目录,例如~/lib
,然后运行:或者,如果您愿意
,程序应该加载您的私有库而不是系统库。
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:Or if you prefer
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,