libstdc++ GLIBCXX 版本错误

发布于 2024-11-30 23:33:49 字数 415 浏览 3 评论 0原文

当我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

注定孤独终老 2024-12-07 23:33:49

在家里链接程序时,您似乎正在使用标准库作为共享库(默认行为)。

因此,链接器只是解析一些符号并执行另一个操作,而不是真正“链接”库,同时将库的实际加载延迟到运行时。

当您在大学计算机上执行程序时,加载程序(实际上将程序加载到内存中并引发主线程的程序)会查找程序所需的库并尝试加载它们(查找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.

二智少女 2024-12-07 23:33:49

大学计算机上的 libstdc++.so.6 版本太旧。您有两个选择:

  1. 使用 -static 进行静态链接。然后,C++ 库将合并到最终的二进制文件中。
  2. 将正确的版本复制到主目录中的某个位置,然后通过在构建时传递 -rpath /path/to/library/directory 或设置 LD_LIBRARY_PATH 环境来引用它变量指向包含较新的 libstdc++.so.6 的目录。

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.
花辞树 2024-12-07 23:33:49

您可以将 /usr/lib/libstdc++.so.6 版本复制到服务器主目录的子目录,例如 ~/lib,然后运行:

$ LD_LIBRARY_PATH=$HOME/lib ./main

或者,如果您愿意

$ export LD_LIBRARY_PATH=$HOME/lib
$ ./main

,程序应该加载您的私有库而不是系统库。

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.

强辩 2024-12-07 23:33:49

您想针对哪些平台进行编译?即“您的计算机”和“大学服务器”?

您可以尝试使用静态链接选项编译您的程序。这将生成一个静态链接的可执行文件,其中已加载所有库依赖项。

干杯,

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,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文