如何安装g ++编译器?


24

我尝试了以下方法:

sudo apt-get install build-essential 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

但是当我编译时,终端显示以下内容:

g++ hello.cpp -o hello
The program 'g++' can be found in the following packages:
 * g++
 * pentium-builder
Try: sudo apt-get install <selected package>

我该怎么办?


我仍然得到相同的结果

Answers:


33

答案在您的问题中:

Try: sudo apt-get install <selected package>

在您的情况下:

sudo apt-get install g++

11
另一种选择是install build-essential,它还包括常用的构建库,而不仅仅是g++,但是如果只需要g++编译器,那么您的命令是正确的。
托马斯·沃德

3
@enedil是的,我做到了,但是仅安装g ++可能会省略编译程序所需的依赖库。您是否实际阅读了我的评论,指出如果答案中的命令不需要其他构建库,它们是正确的?
托马斯·沃德
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.