Ubuntu下编译C/C++文件
2015-09-10 15:46
627 查看
安装GCC 的C/C++编译器
sudo apt-get updatesudo apt-get install build-essential manpages-dev
检测一下是否安装成功
$ whereis gcc
$ which gcc
$ gcc –version
如下
写C
接下来就可以写个helloworld试试了,我的是helloworld.c#include<stdio.h> /* helloworld.c: My first C program on a Linux */ int main(void) { printf("Hello! This is a test prgoram.\n"); return 0; }
然后开始编译
gcc helloworld.c -o helloworld
可以看到生成了一个heloworld编译文件
现在可以运行编译文件了
./helloworld
写C++
#include "iostream" // helloworld2.C - Sample C++ prgoram int main(void) { std::cout << "Hello! This is a C++ program.\n"; return 0; }
那编译时这么写
g++ hellowrld2.C -o helloworld2
运行这么写
./helloworld2
使用调试器GDB
一般如果代码写错了,编译时得到的错误信息不是很多,我们可以使用gdbC文件
gcc -g -Wall helloworld.c -o hellowrld
C++文件
g++ -g -Wall helloworld2.c -o helloworld2
访问www.manpager.com/linux/man1/gcc.1.html获取更多消息
相关文章推荐
- Ubuntu 默认壁纸历代记
- Ubuntu Remix Cinnamon 20.04 评测:Ubuntu 与 Cinnamon 的完美融合
- 关于Ubuntu 11.10启动提示waiting for the network configuration的问题
- 在 Ubuntu 桌面中使用文件和文件夹
- ubuntu下chrome无法同步问题解决
- Ubuntu Linux使用体验
- 使用 GNOME 优化工具自定义 Linux 桌面的 10 种方法
- 以Ubuntu 9.04为例 将工作环境迁移到 Linux
- VirtualBox虚拟机XP与宿主机Ubuntu互访共享文件夹
- 从USB安装Ubuntu Server 10.04.3 图文详解
- Ubuntu 15.04 正式版发布下载
- Linux-Ubuntu 10.04安装Cadence-ic610 方法总结图解
- Ubuntu 12.04和Windows 7双系统安装图解
- 开机出现:grub rescue的修复方法
- Ubuntu连接Android真机调试
- 你应该选择 Ubuntu 还是 Fedora?
- 100 个最佳 Ubuntu 应用(中)
- 看看我的Ubuntu Linux截图
- Ubuntu 12.04 LTS服务器版安装过程及使用图解
- Windows 7/8/8.1 硬盘安装 Ubuntu 14.04 实现双系统