您的位置:首页 > 运维架构 > Linux

linux下编译运行的第一个C

2011-09-02 11:11 316 查看
linux下运行的第一个C程序

root@localhost root]# vi hello.c

进入vim的命令模式,按下键盘的i切换到插入模式,输入如下代码:

#include <stdio.h>

int main()

{

printf("Hello! This is our embeded world!/n");

return 0;

}

按下Esc进入命令模式,输入:wq,自然会保存文件会退回到终端

接下来就是预处理、链接、编译、运行拉

[root@localhost root]# gcc -E hello.c -o hello.i //预处理

[root@localhost root]# gcc -S hello.i -o hello.s //编译不汇编,生成汇编文件

[root@localhost root]# gcc -c hello.s -o hello.o //编译不链接。生成目标文件

[root@localhost root]# gcc hello.o -o hello //生成执行文件

[root@localhost root]# ./hello //运行执行文件

Hello! This is our embeded world! //这就是输出的结果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: