linux下编译运行的第一个C

 

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!                  //这就是输出的结果

你可能感兴趣的:(linux下编译运行的第一个C)