9

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!

paul
  • 651
  • 1
  • 5
  • 12

1 Answers1

13

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.

Guillaume
  • 2,044
  • 12
  • 11
  • Perfect, worked right away! I'm not sure why I didn't think to look in the associated lib directory instead of mucking about in /usr/lib... hindsight is always 20/20. Anyway, thanks again, I really appreciate the help! – paul May 30 '13 at 01:54
  • @Guillaume So how does ld.so work? Do you just run `ld.so --library-path /app/gcc/4.8.0/lib` from a terminal and it is always magically used from everywhere on the system for that user just as if it were on `LD_LIBRARY_PATH`? If so, why is that better than using `LD_LIBRARY_PATH`? – David Doria Dec 01 '16 at 14:08
  • @DavidDoria ld.so --library-path blah just invokes the linker with that search path. It does not change the default configuration for the linker (well at least on Linux). If you want to change its default search path, you will probably have to edit /etc/ld.so.conf or something similar. man ld.so will give you all the details. – Guillaume Dec 07 '16 at 22:33