how create makefiles in c++ and why it is used?
A Makefile is a file with a batch of commands used to compile and link (yes, you can use it for other purposes outside of compilation), especially used where there are special compiler options required, or where a program requires the compilation of many files (sometimes thousands), where manual compilation is difficult. In the latter case, the Makefiles themselves are usually computer-generated.
Makefiles are usually called "Makefile" as that is one of the three names that make searches for. If you use another name, you will have to specify it manually to make or compilation will not occur.
Makefiles are not specific to C++; they can be used to compile programs in any language.
The basic structure of a Makefile:
all: makeTarget2
gcc -o /usr/local/bin/myprogram myprogram.c
makeTarget1:
something else
more commands
makeTarget2:
something else
more commands
A Makefile always has the target labelled all, which is run when the user runs make with no make target. Words after the label, on the same line, are other make targets that are run before the body of that label is run (because it is depended on).
Commands follow labels on subsequent lines prefixed using tab characters ("U+0009 CHARACTER TABULATION" only - no spaces!).
Other make targets, not called "all", continue in the same way. One will call these make targets, either by running make makeTargetName, or through dependency (e.g. all depends on makeTarget2).