GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference
Asked Answered
K

4

11

Apologies, I understand questions very similar to this have been asked relatively often, although none of the solutions seem to work for me.When attempting to run any c++ code of a reasonable complexity, I get the above error. The full error message is:

/main: relocation error: ./main: symbol _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference

running another project, I get a very similar error:

./main: relocation error: ./main: symbol _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference

I don't actually have any problem with compilation, as these projects both compile fine. This just happens when I try to run the executable. I thought it was an error with my gcc install, so today I reinstalled it, although that did not help at all. I don't really know what to do to fix this, can anyone offer assistance?

This is the Makefile I'm using to compile one of the projects, I feel this is where the error could be:

CC= g++
CFLAGS= -Wall -g -std=c++11 -lX11 -lpthread
OBJS = main.o Board_Tile.o Sliding_Solver.o

main: $(OBJS)
   $(CC) -o $@ $(OBJS)
%.o : %.cc
   $(CC) $(CFLAGS) -c $^

My gcc version is 5.3.0, I'm running Ubuntu 14.0.4.

Klos answered 23/4, 2016 at 21:19 Comment(1)
What happens if you try to run your program by typing LD_LIBRARY_PATH=/usr/local/lib ./main instead of just ./main?Langlois
C
21

GCC 5.1 or 5.2 (can't remember now, google it) changed C++ ABI. Your standard ubuntu (including libstdc++) is compiled with old ABI.

Your gcc compiler tries to use new ABI. Sometimes it works, most of the time - no.

So, there are 3 ways to compile your code:

1) downgrade gcc

2) add -D_GLIBCXX_USE_CXX11_ABI=0 (cmake example) flag (if you go this way, you should add this flag to every makefile or project you build till you upgrade ubuntu or downgrade gcc)

3) upgrade Ubuntu (tested it, by the way 16.04 goes with new ABI and new gcc by default, I had to ack-grep and remove flag mentioned above from all my pet projects)

also: Understanding GCC 5's _GLIBCXX_USE_CXX11_ABI or the new ABI

P.S. funny thing, the answer is in the question: _ZNSt7__cxx11 : CXX11, though we don't really read error messages.

Chive answered 23/4, 2016 at 21:57 Comment(2)
Perfect! That makefile flag worked like a charm. Downgrading gcc seems like a thing I should do though- would any version in the 4.XX range work?Klos
It depends: if you're working with c++11/14 standard, some things might go wrong because they are not compatible with older gcc (gcc.gnu.org/projects/cxx-status.html#cxx11), I suggest to upgrade.Chive
P
3

before_install:

This workaround is required to avoid libstdc++ errors while running "extended" hugo with SASS support.

  • wget -q -O libstdc++6 http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb
  • sudo dpkg --force-all -i libstdc++6

    install:

  • wget -q -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.46/hugo_extended_0.46_Linux_64bit.deb

  • sudo dpkg -i hugo.deb

I found this answer here, and it worked for me

Protestantism answered 1/4, 2019 at 17:55 Comment(0)
L
1

update libstdc++6 download link to:

http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.12_amd64.deb

Lavalley answered 29/12, 2019 at 15:11 Comment(1)
Why would you download this manually instead of installing it with apt? How do you check that it's the right file and hasn't been messed with in transit?Stonemason
T
1

So I was having the same error on ubuntu 18.04, and these are the steps to fix it:

  1. Run this to check the what is missing
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX

You will get something like

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_3.4.20
GLIBCXX_3.4.21
GLIBCXX_DEBUG_MESSAGE_LENGTH

Then run:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update

sudo apt-get install gcc-5

sudo apt-get upgrade libstdc++6

At least run again to confirm the changes

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX

Torsion answered 17/3, 2020 at 19:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.