Examples of GCC and makefile under Linux (from the compilation of GCC to the introduction of makefile)

Source: Internet
Author: User
Tags save file

First, confirm that the GCC and make packages have been installed

You can use the Whereis command to view:

If the Whereis gcc and whereis make commands have results, you can continue to do so by installing both software.

Second, use GCC compile to run a HelloWorld program (only involves a single file)

You can write a C program in any directory and then compile and run it, I do this instance in my own home directory:

It then goes to the programming interface:

Press the keyboard "I" to enter the editing interface, and then enter the program:

Press ESC (enter command line mode), then enter ": Wq", the colon indicates the start input command, the letter W represents the save file, the letter Q represents the Exit Editor:

Press ENTER to exit the Vim editor, return to the terminal, following the compile run:

C. Run a multi-file program (containing main programs and subroutines) using GCC compilation

Here we have to write two C program files, a file inside write a function, another file in the main function called the first file function, as follows:

The EX_DISPLAY.C code is as follows, and after the same write, ESC then type: WQ exit:

Enter the following main function code:

Then save the exit, as follows to compile the run process:

Iv. using Makefile to solve the problem of multi-file compiling and running

As described in the red box in the previous section, if a program involves a lot of files, each has to write out, it is troublesome, so makefile appeared, please see the tutorial:

After entering makefile's editing interface, enter the following:

Then save the exit and run the Make command:

V. Comparison of Makefile and shell script methods

Some people say that I write all the previous commands into the shell script, not to achieve makefile effect, yes, the final effect is the same, but Makefile has these benefits:

    • Simplify the command of compilation execution (and no gcc–c process)
    • Once make, the next time only the modified files will be compiled, the other files will not be compiled

Others have some advantages, but this second advantage is too big for large projects!

----------------------------------

Transferred from: http://www.crazyant.net/414.html

Examples of GCC and makefile under Linux (from the compilation of GCC to the introduction of makefile)

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.