DEV Community

Cover image for Build C++ project using CMake on Windows
Srecko Kostic
Srecko Kostic

Posted on • Originally published at srele96.Medium

1

Build C++ project using CMake on Windows

Building a basic project structure using CMake and CMakeLists.txt on windows. A short and concise set of steps I did to build and run the C++ project structure.

Description

Using base structure:

building-with-cmake/
building-with-cmake/.gitignore
building-with-cmake/README.md

building-with-cmake/CMakeLists.txt
building-with-cmake/source
building-with-cmake/source/CMakeLists.txt
building-with-cmake/source/main.cpp
Enter fullscreen mode Exit fullscreen mode

Learn to build a project using CMake. At least a small one, like this one.

Goals

Build and run the code.

Build steps

I created this sample on windows machine. I think that is relevant information.

When first opening the directory

Run the steps in the following order:

@REM this is a comment

@REM create directory
mkdir build

@REM go to directory
cd build

@REM setup the project
cmake ..

@REM build the program
cmake --build .

@REM run the program
Debug\building-with-cmake
Enter fullscreen mode Exit fullscreen mode

After we create the build directory

Run the following:

@REM build the program, probably after code change
cmake --build .

@REM run the program
Debug\building-with-cmake
Enter fullscreen mode Exit fullscreen mode

Alternatively, we may have to run one more step. Probably if we
change CMakeLists. I am not sure about that.

@REM setup the project
cmake ..

@REM build the program
cmake --build .

@REM run the program
Debug\building-with-cmake
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay