最近。刚开始学习Linux。下面简单介绍一下在Linux 下实现hello world的几个步骤:
先附上基本的过程
[crazw@Linux ~]$ ls code Documents Music Public Templates 信息安全竞赛报告.doc Desktop Downloads Pictures software Videos [crazw@Linux ~]$ cd code/ [crazw@Linux code]$ ls [crazw@Linux code]$ mkdir hello [crazw@Linux code]$ ls hello [crazw@Linux code]$ vim ./hello/hello.c [crazw@Linux code]$ gcc hello.c -o hello gcc: error: hello.c: No such file or directory gcc: fatal error: no input files compilation terminated. [crazw@Linux code]$ cd hello [crazw@Linux hello]$ gcc hello.c -o hello [crazw@Linux hello]$ ./hello Helllo world
j接下来具体讲一下每个步骤:
首先:通过vim 新建一个 .c 文件。
如下:我是在Code文件夹下,新建一个Hello文件夹然后在用vim见一个hello.c文件:
[crazw@Linux ~]$ cd code/ [crazw@Linux code]$ ls [crazw@Linux code]$ mkdir hello [crazw@Linux code]$ ls hello
然后,按以下“ i ” 进入编辑模式:然后写入基本的代码完成后,按下ESC,再按“ : wq”,此是保存并退出命令。w:保存。q:退出。(这里不多讲,这是vi的基本操作。不多叙述)
再用gcc编译一下生成一个可执行文件 此处命名为:hello
[crazw@Linux code]$ cd hello [crazw@Linux hello]$ gcc hello.c -o hello
最后执行一下 hello文件 看一下结果:
[crazw@Linux hello]$ ./hello Helllo world
好了。初步学习Linux。希望大家勿喷。