1

First of all, know that I'm very new to c++ and Ubuntu.

I have a program that I am trying to compile using GCC (my version is gcc 4.8.4) by using a makefile. The problem is that the executable file is created under a directory it works, but when its copied to any other (or even forced to be created there on the makefile) it says.

/usr/lib/i386-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.20' not found 

Also when i check for versions with strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX, i get:

GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_DEBUG_MESSAGE_LENGTH

As far as I've been reading on the internet the problem is GLIBCXX_3.4.20 is only supported by gcc 4.9 and above while I am using 4.8.4, but still, I don't get why it would work in a specific directory and not in others.

gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4) 

As I don't have permissions to update gcc, I would like to know what can I do to solve this... What things should I avoid to use on the code that are requiring GLIBCXX_3.4.20? Can I force the compiler to use an older version of that lib somehow or include that specific library in the binary file? (I can't understand why it would work in a directory if I don't have the needed lib)

Thanks in advance and sorry if my question is dumb or makes no sense, as I said I'm very new to this all.

4
  • Seems like you have a problem with 32bits and 64bits versions. Dec 3, 2018 at 11:26
  • Doubt we can answer this without being able to see the system or at least more information. You say it works only in one directory but don't tell us what that directory is or where it is or what's in it? Dec 3, 2018 at 11:27
  • The system is 64bits, The directory is a generic one where the binarys are automatically generated on my company. There's nothing more on that dir if I do ls command as people use to move the executables.
    – Blinkoh
    Dec 3, 2018 at 11:36
  • I have been trying commenting and uncommenting all parts of the code and I've got to the answer that the function string.find() is the one giving me that trouble. Tryed changing all the find() to strstr and strchar and the problem works on the directory I told, but still problems when running it outside...
    – Blinkoh
    Dec 3, 2018 at 15:54

2 Answers 2

2

I have been trying commenting and uncommenting all parts of the code and I've got to the answer that the function string.find() is the one giving me that trouble.

Furious activity is no substitute for understanding.

From the symptoms you described, it is clear that you have two separate versions of libstdc++.so.6, and that your program binds to one version when run in a specific directory, and to another when run outside of that directory.

Your first task is then to figure out which versions of libstdc++.so.6 are being used when. You can do that with:

cd /path/to/specific/directory
LD_DEBUG=files,libs /path/to/binary ...args...

and compare the output to

cd /tmp
LD_DEBUG=files,libs /path/to/binary ...args...

Once you know the path to a working libstdc++.so.6, you'll need to figure out why you are using it only some of the time, and not all the time.

Common causes include having a relative path in your LD_LIBRARY_PATH environment variable (bad), or in the RPATH or RUNPATH of the binary itself, or one of the libraries it depends on.

You can examine the RPATH this way:

readelf -d /path/to/binary | egrep 'RPATH|RUNPATH'

Your last step should be to get rid of relative paths (wherever they are coming from -- they are never a good idea), and arrange for the correct version of libstdc++.so.6 to be picked up allways (usually by supplying -Wl,-rpath=/path/to/desired/directory at link time).

Once you've done that, your program should work correctly regardless of which directory you invoked it from.

1
wget https://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.xz

tar xvf gcc-10.2.0.tar.gz
cd gcc-10.2.0
mkdir -p /mnt/distvol/opt/gcc/10.2.0
./configure --with-system-zlib --disable-multilib --enable-languages=c,c++ --prefix=/mnt/distvol/opt/gcc/10.2.0
make -j 2
make install
ln -s /mnt/distvol/opt/gcc/10.2.0/bin/* /usr/bin/ -f
mv /usr/bin/lib64/libstdc++.so.6 /usr/bin/lib64/libstdc++.so.6.bak
strings $(find /mnt/distvol/opt/gcc/10.2.0/ -name "libstdc++.so.6") | grep GLIBCXX_3.4.
ln -s /mnt/distvol/opt/gcc/10.2.0/lib64/libstdc++.so.6 /usr/bin/lib64/libstdc++.so.6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.