ld:无法识别的选项'--push-state--no-needed' [英] ld: unrecognized option '--push-state--no-as-needed'
问题描述
我的构建失败,并显示以下链接器错误消息:
My build fails with the following linker error message:
失败::&& /usr/bin/g ++ -Wall -Wextra -Werror -g -fsanitize =未定义,地址-Wno未使用参数-fsanitize =未定义,地址-rdynamic * .o -o SCE -Wl,-rpath,/opt/qt59 /lib/opt/qt59/lib/libQt5Widgets.so.5.9.1/usr/local/lib/libprotobuf.a -lpthread -lutil -lgrpc ++/opt/qt59/lib/libQt5Gui.so.5.9.1/opt/qt59 /lib/libQt5Core.so.5.9.1&& :
/usr/bin/x86_64-linux-gnu-ld:无法识别的选项'--push-state--no-ne-needed'
FAILED: : && /usr/bin/g++ -Wall -Wextra -Werror -g -fsanitize=undefined,address -Wno-unused-parameter -fsanitize=undefined,address -rdynamic *.o -o SCE -Wl,-rpath,/opt/qt59/lib /opt/qt59/lib/libQt5Widgets.so.5.9.1 /usr/local/lib/libprotobuf.a -lpthread -lutil -lgrpc++ /opt/qt59/lib/libQt5Gui.so.5.9.1 /opt/qt59/lib/libQt5Core.so.5.9.1 && :
/usr/bin/x86_64-linux-gnu-ld: unrecognized option '--push-state--no-as-needed'
您可以在此处查看完整的构建日志.错误出现在2211行中,版本打印在2104ff行中.
You can see the full build log here. The error is in line 2211 and versions are printed in lines 2104ff.
哪个工具导致错误?
-
gcc 7.3.0
是否使用了错误的链接器标志?ld
文档表示--push-state
和是单独的命令. -
ld 2.28
是否太旧,无法理解链接器标志?
- Is
gcc 7.3.0
using an incorrect linker flag? Theld
documentation indicates that--push-state
and--no-as-needed
are separate commands. - Is
ld 2.28
too old to understand the linker flag? The change log doesn't list anything that seems related. - The command
&& /usr/bin/g++
looks odd, it should be/usr/bin/g++
. Usingmake
instead ofninja
shows the same linking error.
它在同时使用gcc 7.3.0
和ld 2.30
的Debian测试中正确构建,但是对于Ubuntu Trusty来说似乎没有有效的binutils-2.30
ppa.
It builds correctly on Debian testing which is using gcc 7.3.0
as well and ld 2.30
, but there doesn't seem to be a working binutils-2.30
ppa for Ubuntu Trusty.
如何在Travis上成功构建项目?
How do I successfully build my project on Travis?
推荐答案
GCC 7已通过 Ubuntu工具链测试PPA (适用于16.04)获得. .1和14.04).
GCC 7 is fixed with 7.3.0-16ubuntu3 (tested on Ubuntu 18.04). This version is available though the Ubuntu Toolchain Test PPA (for 16.04.1 and 14.04).
仅通过Make进行了测试,但它也可以与Ninja一起使用.启用了Sanitizer,ASan和UBsan.
Tested with Make only, but it should work with Ninja too. Both Sanitizer, ASan and UBsan, enabled.
更改日志尽管
gcc-7(7.3.0-16ubuntu3)仿生; urgency = medium
gcc-7 (7.3.0-16ubuntu3) bionic; urgency=medium
- 从gcc-7-branch更新到SVN 20180415(r259389).
- 修复PR libstdc ++/85222.
- Update to SVN 20180415 (r259389) from the gcc-7-branch.
- Fix PR libstdc++/85222.
更新:
GCC 7( 7.3.0-16ubuntu3 )在 Ubuntu 16.04和.
Update:
GCC 7 (7.3.0-16ubuntu3) is still broken on Ubuntu 16.04 and earlier.
您可以采取以下措施:
此问题已在 Ubuntu 18.04(LTS) 的Gcc7上解决.
The problem is fixed on Ubuntu 18.04 (LTS)'s Gcc7.
如果无法更新,例如.在CI系统上运行,仍然可以选择使用 Docker 和最新的Ubuntu.
If an update is not possible, eg. running on a CI system, it's still an option to use Docker and an up-to-date Ubuntu.
仅当在启用UB Sanitizer的情况下使用GCC7时,才会出现问题.正如 tobias-brüll 在评论中指出的那样: 关闭 UB Sanitizer 可防止该错误.
The Problem occurs only when using GCC7 with UB Sanitizer enabled. As tobias-brüll noted in the comments: Turning the UB Sanitizer off prevents the error.
由 makerj 发布的另一种解决方法:使用 Gold Linker 不会引起问题.
Another workaround posted by makerj: Using the Gold Linker doesn't cause the problem.
例如.在 CMake 上通过
CMAKE_EXE_LINKER_FLAGS
:cmake -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=gold ..
这篇关于ld:无法识别的选项'--push-state--no-needed'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!