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