One of the things Sam suggested to learn/use with C++ is make and cmake. I’ve come across make before, but not cmake, this blog is going to be about learning the basics of both.
The following is a simple program that I made to start with make.
Now for the
Now all that needs to be done is run the
make command. After running the newly compiled binary
main, we get the expected output;
Hello world from Makefile example!.
Next is to create a cmake example using the same program.
// CMakeLists.txt cmake_minimum_required (VERSION 3.10) project (hw_cmake_example) add_executable( main main.cpp hello.cpp hello.h )
CMakeLists.txt file done, now to create a build directory
mkdir build && cd build, then to run the command
cmake ... This creates a few files, one of which is a
Makefile. We can now run
make and then run the compiled binary
main, which gives the expected output;
Hello world from the CMake example!.