Linux第一个c语言编程

Linux 中最重要的软件开发工具是 GCCGCC  GNU  C  C++ 编译器。实际上,
GCC 能够编译三种语言:CC++  Object C语言的一种面向对象扩展)。利用 gcc 
令可同时编译并连接 C  C++ 源程序。


查看是否安装有 gcc

[root@localhost test]# rpm -q gcc
gcc-4.4.7-4.el6.x86_64

编辑程序

[root@localhost test]# vi hollw

这时,按下键盘上的 i 键,从vi编辑器的命令模式进入到插入模式。

输入下面的小程序

i nclude <stdio.h>

i nclude <stdlib.h>

int main ()
{
    printf ("Hello, world!\n");

    return 0;
}

输入完成,按Esc退出插入模式,回到了命令模式,按“ Shitf+冒号键”,输入命令 wq ,即可退出vi编辑器。

查看文件编辑后的文件

[root@localhost test]# ls -l

-rw-r--r--    1 root  root       106 Jul 28 12:47 hellow

还是不放心?那用cat命令进去看看。大笑

[root@localhost test]# cat hellow

#include<stdio.h>
#include<stdlib.h>


int main()
{
        printf("Hello,World!\n");
        return 0;
}

我们再把文件的后缀名改为点c,采用命令mv。吐舌头

[root@localhost test]# mv hellow hellow.c

生成可执行文件

则只需在命令键入 gcc -o hello hello.c 就可以编译、连接并生成一个可执行文件 
hello
[root@localhost test]#   gcc -o   hww    hello.c
[root@localhost test]#    ./hww

Hello, world!

注意命令是“点斜线hww”不要漏一点。

[root@localhost test]# ls -l

-rwxr-xr-x    1 root  root      6426 Jul 28 12:50 hww

微笑

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值