Use vim and GCC to compile C programs in your Mac

Source: Internet
Author: User
Tags macbook

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.