How to Install and Use CMake on Linux for C++ Projects
HardReset.InfoJanuary 17, 20264 min78 views
8 connections·11 entities in this video→Installing CMake on Linux
- 💻 Open your terminal to begin the installation process.
- 🐧 On Ubuntu and Debian-based systems, use the command
sudo apt install cmake. - ⚠️ For other distributions like Fedora, you might use
dnf install cmakeor similar package manager commands; the core command to install iscmake. - ✅ After installation, verify it by typing
cmake --versionto see the installed version.
Creating a Simple C++ Project
- 📁 Create a new project directory using
mkdir cmake-demoand navigate into it withcd cmake-demo. - 📝 Create a C++ source file, for example
main.cpp, using a text editor likenano. - 💡 Inside
main.cpp, write a basic C++ program, including<iostream>and amainfunction that prints "Hello CMake!".
Configuring and Building with CMakeLists.txt
- 📄 Create a
CMakeLists.txtfile in the project root. - ⚙️ In
CMakeLists.txt, define the minimum CMake version required (e.g.,cmake_minimum_required(VERSION 3.10)), set the project name (e.g.,project(hello-cmake)), and add your executable usingadd_executable(hello main.cpp). - 🏗️ It's recommended to create a separate build directory:
mkdir buildandcd build. - 🔗 Inside the build directory, run
cmake ..to configure the project. - 📦 Compile the project using the command
make.
Running the Executable
- ▶️ After successful compilation, run the executable from the build directory. If your executable is named
hello, you can run it with./hello. - ✅ The output should display "Hello CMake!", confirming that your project was built and executed successfully using CMake on Linux.
Knowledge graph11 entities · 8 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover · drag to explore
11 entities
Chapters2 moments
Key Moments
Transcript16 segments
Full Transcript
Topics11 themes
What’s Discussed
CMakeLinuxC++Build SystemUbuntuDebianFedoraTerminal CommandsProject ConfigurationExecutable CompilationSoftware Development
Smart Objects11 · 8 links
Products· 7
Location· 1
Medias· 2
Concept· 1