Skip to main content

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 cmake or similar package manager commands; the core command to install is cmake.
  • ✅ After installation, verify it by typing cmake --version to see the installed version.

Creating a Simple C++ Project

  • 📁 Create a new project directory using mkdir cmake-demo and navigate into it with cd cmake-demo.
  • 📝 Create a C++ source file, for example main.cpp, using a text editor like nano.
  • 💡 Inside main.cpp, write a basic C++ program, including <iostream> and a main function that prints "Hello CMake!".

Configuring and Building with CMakeLists.txt

  • 📄 Create a CMakeLists.txt file 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 using add_executable(hello main.cpp).
  • 🏗️ It's recommended to create a separate build directory: mkdir build and cd 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