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