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)