Linux-Project compilation with Make

Source: Internet
Author: User

First set up your own working directory.


Then create the main function main.cpp


Then write the sinValue.h and cosValue.h function files





Compile and run in the traditional way first



Then use make to write the makefile file first


Delete the original generated file, run make


Let's try a few more basic syntax and variables for make.


The basic makefile code is this:

Target: Target 1 target file 2<tab> gcc-o target file   2 to create the run file destination file 1

In the makefile the # represents the annotations;
<tab> requires the first byte of the command line (such as the GCC compiler command);
A ":" is required between the target and the dependent file (the target file).

Continue with the above program to test, add in Makefile:


See the results of running make with the new target (clean) test


If you want to know the target file before compiling the main program, you can enter "make clean main":



You can simplify makefile like shell script:


Unlike the syntax of Bash shell script, the basic syntax for a variable is:

1, variable and variable content with "=" separated, and both sides can have spaces;
2, the left of the variable can not have <tab>, such as the first line of the above example LIBS the left can not be <tab>;
3, variable and variable content in "=" on both sides can not have ":";
4, in the habit, the variable is best to "capital" mainly;
5, when using variables, ${variable} or $ (variable) use;
6, the environment variables in the shell can be applied, such as the CFLAGS of the mentioned variable!
7. Variables can also be given in command-line mode.


The rules for environment variables are as follows:

1. The environment variables added after the make command are preferred;
2, makefile the environment variables specified in the second;
3, the shell originally has the environment variable third.

In addition, there are some special variables to be aware of:

[email protected]: represents the current subject (target)

So I can also change the makefile to:




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux-Project compilation with Make

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.