Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Running the Executable | Creating and Building Projects
Introduction to CMake

bookRunning the Executable

After building your project with CMake, the compiled program is placed inside the build directory, not in your source folder. This is part of the out-of-source build approach, which keeps your project clean and organized.

# project-root/
# β”œβ”€β”€ CMakeLists.txt
# β”œβ”€β”€ main.c
# └── build/
#     β”œβ”€β”€ Makefile
#     β”œβ”€β”€ cmake_install.cmake
#     β”œβ”€β”€ CMakeFiles/
#     └── MyApp        (Linux)
#     └── MyApp.exe    (Windows)

The file named MyApp (Linux) or MyApp.exe (Windows) is your compiled program and is ready to run.

Running on Linux

To run the program on Linux, navigate to the build directory and execute it using ./:

cd build
./MyApp

Running on Windows

On Windows, open Command Prompt or PowerShell, move to the build folder, and run:

MyApp.exe

Program Output

If everything works correctly, you should see output similar to:

Hello from CMake!
Note
Note

If your terminal says Permission denied on Linux, make the file executable:

chmod +x MyApp
question mark

Where is the executable typically found after building a CMake project?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 4

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain what an out-of-source build is?

What should I do if I don't see the compiled program in the build directory?

How do I clean or rebuild my project with CMake?

bookRunning the Executable

Swipe to show menu

After building your project with CMake, the compiled program is placed inside the build directory, not in your source folder. This is part of the out-of-source build approach, which keeps your project clean and organized.

# project-root/
# β”œβ”€β”€ CMakeLists.txt
# β”œβ”€β”€ main.c
# └── build/
#     β”œβ”€β”€ Makefile
#     β”œβ”€β”€ cmake_install.cmake
#     β”œβ”€β”€ CMakeFiles/
#     └── MyApp        (Linux)
#     └── MyApp.exe    (Windows)

The file named MyApp (Linux) or MyApp.exe (Windows) is your compiled program and is ready to run.

Running on Linux

To run the program on Linux, navigate to the build directory and execute it using ./:

cd build
./MyApp

Running on Windows

On Windows, open Command Prompt or PowerShell, move to the build folder, and run:

MyApp.exe

Program Output

If everything works correctly, you should see output similar to:

Hello from CMake!
Note
Note

If your terminal says Permission denied on Linux, make the file executable:

chmod +x MyApp
question mark

Where is the executable typically found after building a CMake project?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 4
some-alt