admin管理员组文章数量:1794759
ubuntu如何编写C++程序
一、检查是否安装有g++ gcc 编译器
终端输入
g++ -v如果提示没有安装,会有如下提示
Command ‘g++’ not found, but can be installed with:
sudo apt install g++
可以按照提示安装,输入
sudo apt install g++g++安装结束后,gcc会自动安装上,输入g++ -v 和gcc -v检查,查看版本号。
二、重新安装vim如果你的vim出现了上下左右箭头变成ABCD的清况,则需要重新安装vim, 具体方法参考这篇博客:mingshiqiang.blog.csdn/article/details/84557981
三、编写代码vim hello.cpp
输入如下代码:
#include <iostream> using namespace std; int main() { cout<<"Hello world!"<<endl; return 0; } 四、编译代码: gcc hello.cpp -lstdc++ -o hello或
g++ hello.cpp -o hello 五、运行编译之后会产生二进制文件hello, 输入以下命令运行:
./hello注意:这里是输入"./hello"而不是hello
六、make编译除了使用第四步的编译方法,还可以使用make命令进行编译,例如
make hello此时会自动找到hello.cpp进行编译,如果没有安装make会有如下提示 Command ‘make’ not found, but can be installed with:
sudo apt install make # version 4.2.1-1.2, or sudo apt install make-guile # version 4.2.1-1.2 按照提示安装make即可
sudo apt install make再运行make hello即可产生二进制文件hello 注意:如果已经产生了hello, 需要先删掉,rm hello
版权声明:本文标题:ubuntu如何编写C++程序 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686864308a111939.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论