如何修复 gcc 编译 127 错误?sudo apt-get install g++ 不起作用

如何修复 gcc 编译 127 错误?sudo apt-get install g++ 不起作用

*强调文字*当我尝试运行程序时出现以下错误。

ubuntu@ubuntu-VirtualBox:~/Desktop$ make
g++ -Wall -Wno-switch -I. -g   -c -o pass.o pass.cpp
make: g++: Command not found
make: *** [pass.o] Error 127

我无法安装 gcc 4.8.2,因为它说找不到它。我安装了 4.8

我做了以下来安装 gcc

sudo add-apt-repository ppa:ubuntu-toolchain-f/test
sudo apt-get update
sudo apt-get install gcc-4.8

接下来我做了

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave     /usr/bin/g++ g++ /usr/bin/g++-4.6 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --config gcc

我唯一能想到的是,当我输入命令时,我没有 4.8海湾合作委员会它说
gcc 版本 4.8.1(Ubuntu 4.8.1-2ubuntu1~12.04)

好的我运行:

ubuntu@ubuntu-VirtualBox:~$ sudo apt-get install g++
Reading package lists... Done
Building dependency tree       
Reading state information... Done
g++ is already the newest version.
g++ set to manually installed.
The following package was automatically installed and is no longer required:
thunderbird-globalmenu
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 293 not upgraded.

ubuntu@ubuntu-VirtualBox:~$ g++ -v
The program 'g++' can be found in the following packages:
* g++
* pentium-builder
Try: sudo apt-get install <selected package>

ubuntu@ubuntu-VirtualBox:~/Desktop$ g++ --help | grep version
The program 'g++' can be found in the following packages:
* g++
* pentium-builder
Try: sudo apt-get install <selected package>
ubuntu@ubuntu-VirtualBox:~/Desktop$ g++ --version
The program 'g++' can be found in the following packages:
* g++
* pentium-builder
Try: sudo apt-get install <selected package>
ubuntu@ubuntu-VirtualBox:~/Desktop$ ^C
ubuntu@ubuntu-VirtualBox:~/Desktop$

此命令安装

sudo apt-get install g++-4.4 libstdc++6-4.4-dev 4.4 (I would like 4.8)

ubuntu@ubuntu-VirtualBox:~/Desktop$ sudo apt-get install g++-4.4 libstdc++6-4.4-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
cpp-4.4 gcc-4.4 gcc-4.4-base
Suggested packages:
gcc-4.4-locales g++-4.4-multilib gcc-4.4-doc libstdc++6-4.4-dbg
gcc-4.4-multilib libmudflap0-4.4-dev libgcc1-dbg libgomp1-dbg
libmudflap0-dbg libcloog-ppl0 libppl-c2 libppl7 libstdc++6-4.4-doc

The following NEW packages will be installed:
cpp-4.4 g++-4.4 gcc-4.4 gcc-4.4-base libstdc++6-4.4-dev
0 upgraded, 5 newly installed, 0 to remove and 292 not upgraded.
Need to get 13.0 MB of archives.
After this operation, 33.4 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main gcc-4.4-base i386 4.4.7-1ubuntu2 [12.0 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise/main cpp-4.4 i386 4.4.7-1ubuntu2 [3,606 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu/ precise/main gcc-4.4 i386 4.4.7-1ubuntu2 [3,079 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu/ precise/main libstdc++6-4.4-dev i386 4.4.7-1ubuntu2 [1,494 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu/ precise/main g++-4.4 i386 4.4.7-1ubuntu2 [4,780 kB]
Fetched 13.0 MB in 3s (3,563 kB/s)   
Selecting previously unselected package gcc-4.4-base.
(Reading database ... 222776 files and directories currently installed.)
Unpacking gcc-4.4-base (from .../gcc-4.4-base_4.4.7-1ubuntu2_i386.deb) ...
Selecting previously unselected package cpp-4.4.
Unpacking cpp-4.4 (from .../cpp-4.4_4.4.7-1ubuntu2_i386.deb) ...
Selecting previously unselected package gcc-4.4.
Unpacking gcc-4.4 (from .../gcc-4.4_4.4.7-1ubuntu2_i386.deb) ...
Selecting previously unselected package libstdc++6-4.4-dev.
Unpacking libstdc++6-4.4-dev (from .../libstdc++6-4.4-dev_4.4.7-1ubuntu2_i386.deb) ...
Selecting previously unselected package g++-4.4.
Unpacking g++-4.4 (from .../g++-4.4_4.4.7-1ubuntu2_i386.deb) ...
Processing triggers for man-db ...
Setting up gcc-4.4-base (4.4.7-1ubuntu2) ...
Setting up cpp-4.4 (4.4.7-1ubuntu2) ...
Setting up gcc-4.4 (4.4.7-1ubuntu2) ...
Setting up g++-4.4 (4.4.7-1ubuntu2) ...
Setting up libstdc++6-4.4-dev (4.4.7-1ubuntu2) ... 

我尝试用 4.8 替换 4.4,但不起作用。更重要的是,使用上述 4.4 命令后,我仍然收到 127 错误。

过去一个月我一直在学习编程,所以当你回答时请知道我是一个新手,并且对很多事情都不太了解。

答案1

您需要安装g++或一些类似命名的包来编译 c++ 代码。

答案2

安装 g++。例如,可以通过以下方式完成

sudo apt-get install g++ 

不确定您是否真的需要特定版本。大多数情况下,系统默认版本应该可以。

答案3

这与 g++ 无关。检查是否没有多余的空格或换行符。如果一切都遵循Makefile标准应该没问题。另外,请检查您是否正确指定了路径。

我希望我能帮助别人,因为我认为你已经解决了这个问题。

答案4

您可能需要通过执行来安装 build-essentials sudo apt-get install build-essential。如果您有全新安装并想要编译某些内容,则会出现错误#1

相关内容