1. 程式人生 > 其它 >報錯:gcc: error trying to exec ‘cc1plus‘: execvp: 沒有那個檔案或目錄

報錯:gcc: error trying to exec ‘cc1plus‘: execvp: 沒有那個檔案或目錄

原因可能是gcc 與g++版本不匹配

查詢版本:

gcc --version
g++ --version

若確定版本不匹配,則開始下載對應版本的g++:

sudo apt install g++-8

若電腦存有多個版本的g++版本:
可以分配優先順序:

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50   
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 70
sudo update-alternatives --install /usr/bin/
g++ g++ /usr/bin/g++-8 80

然後切換g++版本:

sudo update-alternatives --config g++

在這裡插入圖片描述
注: 切換gcc的操作也是一樣的,例如切換gcc版本:

sudo update-alternatives --config gcc

若只想存在一個版本,刪除其他多餘版本:

sudo apt install gcc-8
sudo update-alternatives --config gcc
sudo update-alternatives --remove-all gcc
sudo update-alternatives --install /usr/
bin/gcc gcc /usr/bin/gcc-8 10 sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-8 10