c++ Unable to get CMake Tutorial example to compile
Step 1: Install CMake and a C++ Compiler
Step 2: Create a new directory for your project and navigate to it
Step 3: Create a file named CMakeLists.txt
in the project directory with the following content:
cmake_minimum_required(VERSION 3.10)
# Set the project name and version
project(Tutorial VERSION 1.0)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Add the executable
add_executable(Tutorial tutorial.cxx)
Step 4: Create a file named tutorial.cxx
in the project directory with the following content:
#include <iostream>
int main() {
std::cout << "Hello, CMake Tutorial!" << std::endl;
return 0;
}
Step 5: Open a terminal and navigate to the project directory
Step 6: Run the following commands in the terminal:
mkdir build
cd build
cmake ..
cmake --build .
Step 7: Run the compiled executable:
./Tutorial