1. Open Terminal
2. Enter the following command to enter the VIM editor:
Vim A.C
3. Enter the editor and press I to enter insert mode, and then type the following code:
#include <stdio.h>int main () {printf ("\nhelloworld!\n\n"); return 0 ;}
4. Press ESC to exit edit mode, and then type : Wq, Exit and save the A.C you just edited
5. Enter the following code in the terminal to compile the A.C into an executable file
GCC A.c-o A
6, enter ./A and then enter, you can see the execution results of the program A.C: print out Hello world! at the terminal This sentence.
macbook-pro-2: ~ mac$./Ahelloworld! MacBook-pro-2: ~ mac$
Note: The code for step 5th above is actually made up of four steps:
(1) Preprocessing: Use-e to generate. I files:
GCC-E A.c-o A.I
(2) Assembly: use-S to generate. s files:
Gcc-s A.i-o A.S
(3) Compile: Generate. o Files using-c:
Gcc-c A.s-o A.O
(4) Connection: Use-o to generate the executable file:
GCC A.o-o A
Use vim and GCC to compile C programs in your Mac