Question

I am trying to understand what is the purpose of making files using commands such as cmake .. and make, I have tried looking online but there is no concise explanation on its purpose that i could find.

Also, is it necessary to use make on a project folder that is not built in order to use the source (C++) in other projects.

I know this may be a simplistic question, but as i am fairly new to building files, any information or references would be much appreciated.

Was it helpful?

Solution

If your program consists of a only a few files that can be built with a simple command line invoking the compiler, then make may be superfluous. However, in large projects you may have dozens of files that require complex compiler and linker options, then make or a similar tool becomes a necessity. Consider, if you have a project with 50 C++ source files, and you change just one of them, you don't want to have re-compile all of them. You'd much rather just re-compile the one file that changed and re-link with the existing object files for the rest of them. Tools like make automatically take care of chores like that.

The make language has a number of warts, and I don't think it is anybody's favorite programming language. It is also very tricky to write a makefile that will work on multiple platforms, say Linux, OS X, and Windows. Tools like cmake can be used to generate makefiles that will work on multiple platforms, and lets you describe the process of building your software in a language that is arguably less ugly than make proper.

OTHER TIPS

make is sort of a batch process for compiling/linking/building, etc. You could do all of these steps manually, or you can just use make.

More info here: http://c.learncodethehardway.org/book/ex2.html and http://www.gnu.org/software/make/

Until your project is small, it is very easy to build it without any makefiles. But imagine your projects has 200 source files that you've divided in to a number of static and dynamic libraries, then passing the names of 200 files to the compiler in a command prompt would be impossible. Also you can create a batch file which builds your projects. But make files are superior to batch files. Particularly, when you use cmake your source code can be built with any compiler easily. That is why large projects use makefiles.

Note: If you use any convinient IDE like Visual Studio, you'll not often feel the need of writing makefiles, as the IDE makes it easy for you.

Licensed under: CC-BY-SA with attribution
scroll top