简体   繁体   English

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

[英]How to configure libstdc++ with GCC 4.8?

A while back, I decided to upgrade to GCC 4.8 in order to get an early start on some c++11 features. 前段时间,我决定升级到GCC 4.8,以便尽早开始使用某些c ++ 11功能。 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.) 不过,我有点偏执,并且在几天前的一个项目之前没有真正使用任何新功能(新的编译器似乎工作正常,但可能只是因为我没有使用任何新功能。)

In this new project, when I compiled with the =std=c++11 flag, I had no problems. 在这个新项目中,当我用= std = c ++ 11标志编译时,我没有遇到任何问题。 However, at runtime, I get the error: 但是,在运行时,我收到错误:

./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.18' not found (required by ./main)` ./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: version找不到./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.18'(./main要求)

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. 我认为链接到与GCC 4.8相关联的更现代的libstdc ++库存在问题,但我不能在我的生活中弄清楚如何解决这个或适当的库应该在哪里。 I remember symbolically linking the g++ and gcc binaries to gcc-4.8, which appears to be working, since g++ -v returns: 我记得象征性地将g ++和gcc二进制文件链接到gcc-4.8,这看起来很有效,因为g++ -v返回:

Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/app/gcc/4.8.0/libexec/gcc/i686-pc-linux-gnu/4.8.0/lto-wrapper Target: i686-pc-linux-gnu Configured with: ./gcc-4.8.0/configure --prefix=/app/gcc/4.8.0 Thread model: posix gcc version 4.8.0 (GCC)

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. 另一个在线线程让我看看程序的ldd输出,它确实告诉我链接的libstdc ++库的目录结构与二进制文件的目录结构不同。 I couldn't, however, find the appropriate libstdc++ libraries in the latter, so I'm not sure where to look. 但是,我无法在后者中找到合适的libstdc++库,所以我不确定在哪里查看。 The output for ldd main is: ldd main的输出是:

./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: version GLIBCXX_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)` ./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: version找不到./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: version 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)`

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! 如果有任何问题不清楚或者我忘了一些信息,请告诉我,我会尝试添加它。非常感谢!

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). LD_LIBRARY_PATH设置为库的路径(可能位于/app/gcc/4.8.0/lib或其他地方)。

Use find /app/gcc/4.8.0 -name "libstdc++.so.6" . 使用find /app/gcc/4.8.0 -name "libstdc++.so.6" Add the directory to your LD_LIBRARY_PATH. 将目录添加到LD_LIBRARY_PATH。 eg with the path I mentioned: 例如,我提到的路径:

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). export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/gcc/4.8.0/lib (如果你使用的是类似bourne的shell,这是Linux上的默认值)。

Then try to run your program. 然后尝试运行您的程序。

If it works, you'll probably want to configure your dynamic linker to look in the directory without using LD_LIBRARY_PATH. 如果它工作,您可能希望配置动态链接器以查看目录而不使用LD_LIBRARY_PATH。 See man ld.so for details about how to configure the path. 有关如何配置路径的详细信息,请参阅man ld.so

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM