系统:CentOs6.9
gcc版本:5.1.0
github上拉取vim工程之后,cd src,执行一下命令:
$ ./configure $ sudo make gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -o objects/arabic.o arabic.c gcc: error trying to exec 'cc1': execvp: No such file or directory make: *** [objects/arabic.o] Error 1
发现找不到cc1。全局找下cc1在哪:
$ sudo find / -name cc1 /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/cc1 /usr/libexec/gcc/x86_64-redhat-linux/4.4.4/cc1 /root/software/gcc-5.1-build/gcc/cc1 /root/software/gcc-5.1-build/stage1-gcc/cc1 /root/software/gcc-5.1-build/prev-gcc/cc1
建立一个软连接:
$ sudo ln -s /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/cc1 /usr/bin/cc1
重新编译一下:
$ sudo make gcc -c -I. -Iproto -DHAVE_CONFIG_H -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -o objects/arabic.o arabic.c In file included from os_unix.h:21:0, from vim.h:246, from arabic.c:16: /usr/include/stdio.h:34:21: fatal error: stddef.h: No such file or directory compilation terminated. make: *** [objects/arabic.o] Error 1
发现还是有问题,而且这个报错报在了库文件
全局找下这个文件:
$ sudo find / -name stddef.h /usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/include/stddef.h /usr/include/linux/stddef.h /usr/lib/gcc/x86_64-redhat-linux/4.4.4/include/stddef.h /root/software/gcc-5.1-build/gcc/include/stddef.h /root/software/gcc-5.1-build/stage1-gcc/include/stddef.h /root/software/gcc-5.1-build/prev-gcc/include/stddef.h /root/software/gcc-5.1.0/gcc/ginclude/stddef.h /root/software/gcc-5.1.0/libstdc++-v3/include/c_compatibility/stddef.h
发现是能找到,不过报错的文件的位置,是/usr/include/stdio.h,感觉是路径问题了。
尝试用sudo权限运行./configure:
$ sudo ./configure configure: loading cache auto/config.cache checking whether make sets $(MAKE)... (cached) yes checking for gcc... (cached) gcc checking whether the C compiler works... no configure: error: in `/home/haiming.li/opensource/vim/src': configure: error: C compiler cannot create executables See `config.log' for more details
同样通过find命令,找到config.log所在的位置是src/auto下面,打开看看:
感觉很莫名的报错,而且为何sudo与非sudo执行的时候结果差别那么大呢?
猜测是sudo的gcc跟非sudo下的gcc,版本不一致,尝试验证下:
$ which gcc /usr/local/bin/gcc $ sudo which gcc /usr/bin/gcc
果然,sudo和非sudo下,gcc调用的执行程序不一样。/usr/local/bin/gcc --version 和 /usr/bin/gcc --version的执行结果是一样的,这个比较莫名。不过如果做下软连接,我相信能解决问题。
先对原来的/usr/bin下的gcc做下备份:
$ cd /usr/bin/
$ sudo mv gcc gcc_bak
$ sudo ln -s /usr/local/bin/gcc gcc
继续:
$ ./configure
$ sudo make
然后报了类似这样的错误:
/opt/local/bin/gcc-mp-4.8 -c -I. -Iproto -DHAVE_CONFIG_H -I/usr/local/include -g -O2 -D_FORTIFY_SOURCE=1 -o objects/buffer.o buffer.c In file included from vim.h:302:0, from buffer.c:28: auto/osdef.h:18:12: error: conflicting types for 'printf' extern int printf __ARGS((char *, ...));
google之后,只发现了一个日文网页,而且说得好像不是一个问题,灵机一动下,make clean了一下,然后make就通过了,接着
$ sudo make install
执行下vim:
$ vim
-bash: /usr/bin/vim: No such file or directory
在编译日志里面找了找,感觉vim应该是在/usr/local/bin/vim:
$ /usr/local/bin/vim --version VIM - Vi IMproved 8.1 (2018 May 17, compiled May 28 2018 15:26:31) Included patches: 1-22... 果然在这里,做下软连接: $ sudo ln -s /usr/local/bin/vim /usr/bin/vim
OK,大功告成,手动编译vim8.1搞定。