问题
编译程序时遇到问题:
/bin/ld: this linker was not configured to use sysroots
collect2: error: ld returned 1 exit status
解决
- 升级
binutils
分析
查询了一下,这篇文章 提到该问题的原因是在编译安装ld
时没有配置sysroot
参数。
那么可能的解决方式是重新安装ld
链接器。
查看一下ld
的版本。这里采用的方式是查找能够提供ld
的程序包:
[root: ~]# yum whatprovides ld
Loaded plugins: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Loading mirror speeds from cached hostfile
binutils-2.27-43.base.el7.x86_64 : A GNU collection of binary utilities
Repo : base
Matched from:
Filename : /usr/bin/ld
binutils-2.27-43.base.el7_8.1.x86_64 : A GNU collection of binary utilities
Repo : updates
Matched from:
Filename : /usr/bin/ld
binutils-2.25.1-22.base.el7.x86_64 : A GNU collection of binary utilities
Repo : installed
Matched from:
Filename : /bin/ld
binutils-2.25.1-22.base.el7.x86_64 : A GNU collection of binary utilities
Repo : installed
Matched from:
Filename : /usr/bin/ld
查询结果说明当前的ld
链接器版本为2.25.1-22
,并非最新版本 2.27-43
。
受此启发,更新一下binutils
:
[root: ~]# yum upgrade binutils
Loaded plugins: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package binutils.x86_64 0:2.25.1-22.base.el7 will be updated
---> Package binutils.x86_64 0:2.27-43.base.el7_8.1 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Updating:
binutils x86_64 2.27-43.base.el7_8.1 updates 5.9 M
Transaction Summary
===============================================================================================================================================
Upgrade 1 Package
Total download size: 5.9 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
binutils-2.27-43.base.el7_8.1.x86_64.rpm | 5.9 MB 00:00:00
BDB2053 Freeing read locks for locker 0xcd: 17326/140635147335424
BDB2053 Freeing read locks for locker 0xce: 17326/140635147335424
BDB2053 Freeing read locks for locker 0xcf: 17326/140635147335424
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : binutils-2.27-43.base.el7_8.1.x86_64 1/2
Cleanup : binutils-2.25.1-22.base.el7.x86_64 2/2
Verifying : binutils-2.27-43.base.el7_8.1.x86_64 1/2
binutils-2.25.1-22.base.el7.x86_64 was supposed to be removed but is not!
Verifying : binutils-2.25.1-22.base.el7.x86_64 2/2
Updated:
binutils.x86_64 0:2.27-43.base.el7_8.1
Failed:
binutils.x86_64 0:2.25.1-22.base.el7
Complete!
更新完成之后,重新编译自己的程序,此时问题解决。