已安装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.