1. 程式人生 > >已安裝gcc編譯器,但./configure還是提示找不到編譯器(分析)

已安裝gcc編譯器,但./configure還是提示找不到編譯器(分析)

ive spa assembler action 文件添加 cache assemble 通過 name

1、編譯nginx前, ./configure檢查提示找不到C編譯器

[[email protected] nginx-1.12.2]# ./configure 
checking for OS
 + Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found

2、重裝gcc編譯器後,還是提示找不到C編譯器

[[email protected] nginx-1.12.2]# yum -y reinstall gcc gcc-c++ autoconf automake make
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 
* base: mirrors.aliyun.com * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.163.com Resolving Dependencies --> Running transaction check ---> Package autoconf.noarch 0:2.69-11.el7 will be reinstalled ---> Package automake.noarch 0:1.13.4-3.el7 will be reinstalled
---> Package gcc.x86_64 0:4.8.5-36.el7_6.2 will be reinstalled ---> Package gcc-c++.x86_64 0:4.8.5-36.el7_6.2 will be reinstalled ---> Package make.x86_64 1:3.82-23.el7 will be reinstalled --> Finished Dependency Resolution Installed: autoconf.noarch 0:2.69-11.el7 automake.noarch 0
:1.13.4-3.el7 gcc.x86_64 0:4.8.5-36.el7_6.2 gcc-c++.x86_64 0:4.8.5-36.el7_6.2 make.x86_64 1:3.82-23.el7 Complete! [[email protected] nginx-1.12.2]# ./configure checking for OS + Linux 3.10.0-957.el7.x86_64 x86_64 checking for C compiler ... not found

3、網上找一個hello world C程序代碼,嘗試編譯,提示 cannot find ‘ld‘

[[email protected] ~]# vim hello_world.c
---------------------------------------
#include <stdio.h>
void main()
{
        printf("Hello World \n");
}
---------------------------------------
[[email protected] ~]# gcc hello_world.c 
collect2: fatal error: cannot find ld
compilation terminated.

4、到另一臺可正常編譯電腦,查找ld位置

[[email protected] tmp]# which ld
/usr/bin/ld

5、回到問題機器,發現/usr/bin/ld有這個文件,但是which ld,找不到該文件

[[email protected]]# ll /usr/bin/ld
lrwxrwxrwx. 1 root root 20 May  1 17:22 /usr/bin/ld -> /etc/alternatives/ld
[[email protected] nginx-1.12.2]# which ld
/usr/bin/which: no ld in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

6、ll /usr/bin/ld 發現該文件最終鏈接到/usr/bin/ld.bfd,但是,最終的源文件沒有可執行權限

[[email protected] nginx-1.12.2]# ll /usr/bin/ld
lrwxrwxrwx. 1 root root 20 May  1 17:22 /usr/bin/ld -> /etc/alternatives/ld
[[email protected] nginx-1.12.2]# ll /etc/alternatives/ld
lrwxrwxrwx. 1 root root 15 May  1 17:22 /etc/alternatives/ld -> /usr/bin/ld.bfd
[[email protected] nginx-1.12.2]# ll /usr/bin/ld.bfd 
-rw-rw-rw-. 1 root root 1006216 Oct 30  2018 /usr/bin/ld.bfd

7、給/usr/bin/ld.bfd文件添加執行權限,編譯helloworld成功,./configure 通過gcc環境檢查

[[email protected] ~]# chmod +x /usr/bin/ld.bfd   //添加執行權限
[[email protected] ~]# which ld                   
/usr/bin/ld
[[email protected] ~]# gcc hello_world.c  //編譯成功
[[email protected] ~]# ./
a.out         create.sh       nginx-1.12.2/ .pki/         .ssh/         
[[email protected] ~]# ./a.out   
Hello World 
[[email protected] ~]# cd nginx-1.12.2/
[[email protected] nginx-1.12.2]# ./configure    
checking for OS
 + Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found

8、如果gcc編譯時,提示找不到下面其中一個或多個文件,也可通過 yum -y reinstall binutils 重新安裝工具集

GNU Binutils


The GNU Binutils are a collection of binary tools. The main ones are:

  • ld - the GNU linker.
  • as - the GNU assembler.

But they also include:

  • addr2line - Converts addresses into filenames and line numbers.
  • ar - A utility for creating, modifying and extracting from archives.
  • c++filt - Filter to demangle encoded C++ symbols.
  • dlltool - Creates files for building and using DLLs.
  • gold - A new, faster, ELF only linker, still in beta test.
  • gprof - Displays profiling information.
  • nlmconv - Converts object code into an NLM.
  • nm - Lists symbols from object files.
  • objcopy - Copies and translates object files.
  • objdump - Displays information from object files.
  • ranlib - Generates an index to the contents of an archive.
  • readelf - Displays information from any ELF format object file.
  • size - Lists the section sizes of an object or archive file.
  • strings - Lists printable strings from files.
  • strip - Discards symbols.
  • windmc - A Windows compatible message compiler.
  • windres - A compiler for Windows resource files.

已安裝gcc編譯器,但./configure還是提示找不到編譯器(分析)