linux centos运行C语言程序

1.安装gcc。 yum install gcc

[root@linux ~]# yum install gcc
已加载插件:fastestmirror, langpacks
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
base                                                                                                                                                                                | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                                    | 3.5 kB  00:00:00     
epel                                                                                                                                                                                | 4.7 kB  00:00:00     
extras                                                                                                                                                                              | 2.9 kB  00:00:00     
mysql-connectors-community                                                                                                                                                          | 2.6 kB  00:00:00     
mysql-tools-community                                                                                                                                                               | 2.6 kB  00:00:00     
mysql57-community                                                                                                                                                                   | 2.6 kB  00:00:00     
os                                                                                                                                                                                  | 3.6 kB  00:00:00     
updates                                                                                                                                                                             | 2.9 kB  00:00:00     
(1/3): epel/7/x86_64/updateinfo                                                                                                                                                     | 1.0 MB  00:00:00     
(2/3): epel/7/x86_64/primary_db                                                                                                                                                     | 7.0 MB  00:00:00     
(3/3): updates/7/x86_64/primary_db                                                                                                                                                  |  23 MB  00:00:01     
软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本
无须任何处理

2.创建C语言文件
下述以创建hello.c输出hellowolrd为例
vim hello.c
在hello.c加入C语言代码

#include
int main()
{
printf("Hello World ! ");
return 0 ; 
}

保存退出 !wq

[root@linux ctest]# ls
hello.c 

3.编译 C 语言代码,并生成可执行文件
在hello.c当前目录执行 gcc -o hellotest hello.c 就会生成名为hellotest的可执行文件

[root@linux ctest]# gcc -o hellotest hello.c
[root@linux ctest]# ls
hello.c  hellotest

4.执行可执行文件
在当前目录执行./hellotest

[root@linux ctest]# ./hellotest
Hello World ! 

你可能感兴趣的:(linux,linux,c语言)