如何使用 GCC 4.8 配置 libstdc++?

How to configure libstdc++ with GCC 4.8?(如何使用 GCC 4.8 配置 libstdc++?)

本文介绍了如何使用 GCC 4.8 配置 libstdc++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不久前,我决定升级到 GCC 4.8,以便尽早开始使用一些 c++11 功能.不过,我有点走神了,直到几天前的一个项目才真正使用任何新功能(新编译器似乎工作正常,但这可能只是因为我没有使用任何新功能.)

A while back, I decided to upgrade to GCC 4.8 in order to get an early start on some c++11 features. I got a bit sidetracked, though, and didn't really put any of the new features to use until a project a few days ago (the new compiler seemed to have been working fine, but it may just be because I wasn't utilizing any new functionality.)

在这个新项目中,当我使用 =std=c++11 标志编译时,我没有遇到任何问题.但是,在运行时,我收到错误:

In this new project, when I compiled with the =std=c++11 flag, I had no problems. However, at runtime, I get the error:

./main:/usr/lib/i386-linux-gnu/libstdc++.so.6: 版本找不到GLIBCXX_3.4.18'(./main 要求)`

./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: versionGLIBCXX_3.4.18' not found (required by ./main)`

我认为链接到与 GCC 4.8 相关的更现代的 libstdc++ 库时存在问题,但我终其一生都无法弄清楚如何解决此问题或适当的库应该在哪里.我记得将 g++ 和 gcc 二进制文件符号链接到 gcc-4.8,这似乎正在工作,因为 g++ -v 返回:

I assume that there is a problem linking to a more modern libstdc++ library associated with GCC 4.8, but I can't for the life of me figure out how to fix this or where the appropriate library should be. I remember symbolically linking the g++ and gcc binaries to gcc-4.8, which appears to be working, since g++ -v returns:

使用内置规范.COLLECT_GCC=g++COLLECT_LTO_WRAPPER=/app/gcc/4.8.0/libexec/gcc/i686-pc-linux-gnu/4.8.0/lto-wrapper目标:i686-pc-linux-gnu配置:./gcc-4.8.0/configure --prefix=/app/gcc/4.8.0线程模型:posixgcc 版本 4.8.0 (GCC)

另一个在线帖子让我查看了该程序的 ldd 输出,确实显示链接到的 libstdc++ 库的目录结构不同于二进制文件的目录结构.但是,我无法在后者中找到合适的 libstdc++ 库,所以我不知道去哪里找.ldd main 的输出是:

Another thread online led me to look at the ldd output for the program, which did show me that the directory structure for the libstdc++ libraries being linked to was different than the directory structure for the binaries. I couldn't, however, find the appropriate libstdc++ libraries in the latter, so I'm not sure where to look. The output for ldd main is:

./main:/usr/lib/i386-linux-gnu/libstdc++.so.6: 版本GLIBCXX_3.4.18' 未找到(./main 要求)linux-gate.so.1 => (0xb7791000)libstdc++.so.6 =>/usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb768e000)libm.so.6 =>/lib/i386-linux-gnu/libm.so.6 (0xb7662000)libgcc_s.so.1 =>/lib/i386-linux-gnu/libgcc_s.so.1 (0xb7644000)libc.so.6 =>/lib/i386-linux-gnu/libc.so.6 (0xb749b000)/lib/ld-linux.so.2 (0xb7792000)`

./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: versionGLIBCXX_3.4.18' not found (required by ./main) linux-gate.so.1 => (0xb7791000) libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb768e000) libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb7662000) libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7644000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb749b000) /lib/ld-linux.so.2 (0xb7792000)`

我不确定这是哪里出了问题,我会继续谷歌搜索并四处寻找答案,但如果你们能提供任何帮助,我将不胜感激.如果有任何不清楚的地方或者我忘记了一些信息,请告诉我,我会尽力补充.非常感谢!

I'm not sure exactly where this is going wrong, and I'll continue Googling and looking around for answers, but any help you guys could offer would be greatly appreciated. If anything is unclear about the issue or I forgot some information, just let me know and I'll try to add that in. Thanks so much!

推荐答案

您需要告诉您的动态链接器(它在您运行程序时执行)在哪里可以找到库.将 LD_LIBRARY_PATH 设置为库的路径(可能在 /app/gcc/4.8.0/lib 或其他地方).

You need to tell your dynamic linker (it's executed when you run your program) where to find the library. Set LD_LIBRARY_PATH to the path of the library (probably somewhere under /app/gcc/4.8.0/lib or something).

使用 查找/app/gcc/4.8.0 -name "libstdc++.so.6".将目录添加到您的 LD_LIBRARY_PATH.例如我提到的路径:

Use find /app/gcc/4.8.0 -name "libstdc++.so.6". Add the directory to your LD_LIBRARY_PATH. e.g with the path I mentioned:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/gcc/4.8.0/lib(如果您使用的是 Linux 上默认的类似 bourne 的 shell).

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/gcc/4.8.0/lib (if you're using a bourne-like shell which the default on Linux).

然后尝试运行你的程序.

Then try to run your program.

如果可行,您可能希望将动态链接器配置为在不使用 LD_LIBRARY_PATH 的情况下查看目录.有关如何配置路径的详细信息,请参见 man ld.so.

If it works, you'll probably want to configure your dynamic linker to look in the directory without using LD_LIBRARY_PATH. See man ld.so for details about how to configure the path.

这篇关于如何使用 GCC 4.8 配置 libstdc++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何使用 GCC 4.8 配置 libstdc++?

基础教程推荐