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


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

[root@test 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編譯器

[root@test 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!
[root@test 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'

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

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

[root@xdc tmp]# which ld
/usr/bin/ld

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

[root@test]# ll /usr/bin/ld
lrwxrwxrwx. 1 root root 20 May  1 17:22 /usr/bin/ld -> /etc/alternatives/ld
[root@test 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,但是,最終的源文件沒有可執行權限

[root@test nginx-1.12.2]# ll /usr/bin/ld
lrwxrwxrwx. 1 root root 20 May  1 17:22 /usr/bin/ld -> /etc/alternatives/ld
[root@test nginx-1.12.2]# ll /etc/alternatives/ld
lrwxrwxrwx. 1 root root 15 May  1 17:22 /etc/alternatives/ld -> /usr/bin/ld.bfd
[root@test 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環境檢查

[root@test ~]# chmod +x /usr/bin/ld.bfd   //添加執行權限
[root@test ~]# which ld                   
/usr/bin/ld
[root@test ~]# gcc hello_world.c  //編譯成功
[root@test ~]# ./
a.out         create.sh       nginx-1.12.2/ .pki/         .ssh/         
[root@test ~]# ./a.out   
Hello World 
[root@test ~]# cd nginx-1.12.2/
[root@test 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.

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM