Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. However, at runtime, I get the error:

./main: /usr/lib/i386-linux-gnu/libstdc++.so.6: versionGLIBCXX_3.4.18' not found (required by ./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. I remember symbolically linking the g++ and gcc binaries to gcc-4.8, which appears to be working, since g++ -v returns:

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. 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: 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!

like image 655
paul Avatar asked May 30 '13 01:05

paul


1 Answers

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).

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 (if you're using a bourne-like shell which the default on 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. See man ld.so for details about how to configure the path.

like image 175
Guillaume Avatar answered Oct 16 '22 12:10

Guillaume