C++ GLIBCXX_3.4.21 未在文件 libstdc++.so.6 中定义,带有链接时间参考
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36816570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference
提问by asharkdoctor
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:
抱歉,我理解与此非常相似的问题已被问得比较频繁,尽管似乎没有一个解决方案对我有用。尝试运行任何具有合理复杂性的 C++ 代码时,我收到上述错误。完整的错误信息是:
/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?
我实际上对编译没有任何问题,因为这些项目都编译得很好。这只是在我尝试运行可执行文件时发生。我认为这是我的 gcc 安装错误,所以今天我重新安装了它,尽管这根本没有帮助。我真的不知道该怎么做才能解决这个问题,有人可以提供帮助吗?
This is the Makefile I'm using to compile one of the projects, I feel this is where the error could be:
这是我用来编译其中一个项目的 Makefile,我觉得这可能是错误所在:
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.
我的 gcc 版本是 5.3.0,我运行的是 Ubuntu 14.0.4。
回答by strangeqargo
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.
GCC 5.1 或 5.2(现在不记得了,谷歌它)改变了 C++ ABI。你的标准 ubuntu(包括 libstdc++)是用旧的 ABI 编译的。
Your gcc compiler tries to use new ABI. Sometimes it works, most of the time - no.
您的 gcc 编译器尝试使用新的 ABI。有时它有效,大部分时间 - 不。
So, there are 3 ways to compile your code:
因此,有 3 种方法可以编译您的代码:
1) downgrade gcc
1)降级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)
2)添加-D_GLIBCXX_USE_CXX11_ABI=0(cmake示例)标志(如果你这样做,你应该把这个标志添加到你构建的每个makefile或项目中,直到你升级ubuntu或降级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)
3)升级Ubuntu(测试过,16.04默认使用新的ABI和新的gcc,我不得不确认并从我所有的宠物项目中删除上面提到的标志)
also: Understanding GCC 5's _GLIBCXX_USE_CXX11_ABI or the new ABI
另外:了解 GCC 5 的 _GLIBCXX_USE_CXX11_ABI 或新的 ABI
P.S. funny thing, the answer is in the question: _ZNSt7__cxx11
: CXX11, though we don't really read error messages.
PS 有趣的是,答案就在问题中:_ZNSt7__cxx11
: CXX11,尽管我们并没有真正阅读错误消息。
回答by Hymanson Junior Mkhabela
before_install:
安装前:
This workaround is required to avoid libstdc++ errors while running "extended" hugo with SASS support.
在运行具有 SASS 支持的“扩展”hugo 时,需要此解决方法来避免 libstdc++ 错误。
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
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
须藤 dpkg --force-all -i libstdc++6
安装:
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
我在这里找到了这个答案,它对我有用
回答by user2670800
update libstdc++6 download link to:
将 libstdc++6 下载链接更新为:
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.12_amd64.deb
http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.12_amd64.deb
回答by dannybastos
So I was having the same error on ubuntu 18.04, and these are the steps to fix it:
所以我在 ubuntu 18.04 上遇到了同样的错误,这些是修复它的步骤:
- 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
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get 更新
须藤 apt-get 安装 gcc-5
sudo apt-get 升级 libstdc++6
At least run again to confirm the changes
至少再次运行以确认更改
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX