Skip to content

Understanding cmake and make by compiling a dummy project.

Notifications You must be signed in to change notification settings

savuvictor/cpp-cmake-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Playing with cmake and make on Windows. For learning how to setup cmake and make visit: msys2

Reminder

  • .c files contain the implementation of the code.
  • .h files exist to provide interfaces that allow a file to access functions, global variables, and macros from other files.

Compilation

g++ main.cpp helpers.cpp -o main.exe
./main.exe

Alternatively

g++ -c main.cpp helpers.cpp
g++ main.o helpers.o -o main.exe
./main.exe

Build system

Simple Makefile example

all: main

main: main.o helpers.o
	g++ -o main.exe main.o helpers.o

main.o: main.cpp
	g++ -c main.cpp

helpers.o: helpers.cpp
	g++ -c helpers.cpp

Then you can run make command and finally run ./main.exe

Build system generator

Cmake is a build system generator and a scripting language used to generate make files.

Simple CMakeLists.txt example

cmake_minimum_required(VERSION 3.10)

# set the project name
project(main)

# add executable
add_executable(main main.cpp helpers.cpp)

For this instance I will use Windows and as the generator I will use mingw-make

cd build
cmake .. -G "MinGW Makefiles"
make
./main.exe

About

Understanding cmake and make by compiling a dummy project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published