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