编译cmake源码时提示没有合适的c编译器

从Index of /files下载cmake的各种版本源码,如cmake3.23的cmake-3.23.5.tar.gz,编译源码命令:

tar -zxvf cmake-3.23.5.tar.gz

cd cmake-3.23.5

./configure --prefix=/usr/local/cmake-3.23.5

make && make install

在进行到./configure --prefix=/usr/local/cmake-3.23.5这条命令时,提示没有合适的c编译器:

CMake 3.23.5, Copyright 2000-2022 Kitware, Inc. and Contributors
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C compiler on this system.
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.

按照网上搜查的结果,说没有安装gcc和g++,我查了下gcc的版本:

$gcc -v
The program 'gcc' is currently not installed. You can install it by typing:
sudo apt install gcc
确实是没有安装,

然后用 sudo apt install gcc,却又提示我说已经存在gcc的最新版本了:

$ sudo apt install gcc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
gcc is already the newest version (4:5.3.1-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 80 not upgraded.
 

g++的也是如此。各种操作百般尝试,就是编译不了。后来想着先把gcc和g++卸载再装看看。

sudo apt-get purge:删除已安装的软件包(不保留配置文件),删除软件包,同时删除相应依赖软件包。

$ sudo apt-get purge gcc

$ sudo apt-get purge g++

参考卸载软件包:

【Linux】Ubuntu系统下用apt命令删除/卸载软件包_apt 卸载_Cappuccino-jay的博客-CSDN博客

删除gcc包:(g++也类似)

$ sudo apt-get purge gcc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  build-essential* g++* gcc* gcc-multilib*
0 upgraded, 0 newly installed, 4 to remove and 80 not upgraded.
After this operation, 90.1 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 221913 files and directories currently installed.)
Removing build-essential (12.1ubuntu2) ...
Removing g++ (4:5.3.1-1ubuntu1) ...
update-alternatives: warning: alternative /usr/bin/g++ (part of link group c++) doesn't exist; removing from list of alternatives
update-alternatives: warning: /etc/alternatives/c++ is dangling; it will be updated with best choice
Removing gcc-multilib (4:5.3.1-1ubuntu1) ...
Removing gcc (4:5.3.1-1ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
$ sudo apt-get purge gcc

再安装gcc和g++,此时能正常安装gcc和g++了

$ sudo apt install gcc
$ sudo apt install g++
装完后,使用gcc -v可以看得到gcc的版本了。

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/5/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.12' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-targets=all --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)

此时在运行编译cmake的configure命令,终于可以编下去了。

$ ./configure --prefix=/usr/local/cmake-3.26.4
编译cmake源码时提示没有合适的c编译器_第1张图片

具体cmake源码编译安装:

参考:cmake源码安装_元庆何的博客-CSDN博客

你可能感兴趣的:(linux)