I’m currently doing the Cmake tutorial and I’m stuck at Step1 Exercise 3 but I think I have configured the CMakeLists.txt correctly and do the “cmake …build .”. The “TutorialConfig.h” file is inside the Step1_build directory, and still the error is not locating the “TutorialConfig.h”. Here is my CMakeLists.txt code:
# TODO 1: Set the minimum required version of CMake to be 3.10
cmake_minimum_required(VERSION 3.10)
# TODO 2: Create a project named Tutorial
project(Tutorial VERSION 1.0)
# TODO 7: Set the project version number as 1.0 in the above project command
# TODO 6: Set the variable CMAKE_CXX_STANDARD to 11
# and the variable CMAKE_CXX_STANDARD_REQUIRED to True
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# TODO 8: Use configure_file to configure and copy TutorialConfig.h.in to
# TutorialConfig.h
configure_file(TutorialConfig.h.in TutorialConfig.h)
# TODO 3: Add an executable called Tutorial to the project
# Hint: Be sure to specify the source file as tutorial.cxx
add_executable(Tutorial tutorial.cxx)
# TODO 9: Use target_include_directories to include ${PROJECT_BINARY_DIR}
target_include_directories(Tutorial PUBLIC "${PROJECT_BINARY_DIR}")
tutorial.cxx code:
// A simple program that computes the square root of a number
#include <cmath>
// TODO 5: Remove this line
#include <iostream>
#include <string>
#include "TutorialConfig.h"
// TODO 11: Include TutorialConfig.h
int main(int argc, char* argv[])
{
if (argc < 2) {
// TODO 12: Create a print statement using Tutorial_VERSION_MAJOR
// and Tutorial_VERSION_MINOR
std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
<< Tutorial_VERSION_MINOR << std::endl;
std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
// convert input to double
// TODO 4: Replace atof(argv[1]) with std::stod(argv[1])
const double inputValue = std::stod(argv[1]);
// calculate square root
const double outputValue = sqrt(inputValue);
std::cout << "The square root of " << inputValue << " is " << outputValue
<< std::endl;
return 0;
}
error:
Starting build...
/usr/bin/aarch64-linux-gnu-g++ -fdiagnostics-color=always -g /home/ubuntu/Documents/cmake-3.27.0-rc5-tutorial-source/Step1/tutorial.cxx -o /home/ubuntu/Documents/cmake-3.27.0-rc5-tutorial-source/Step1/tutorial
/home/ubuntu/Documents/cmake-3.27.0-rc5-tutorial-source/Step1/tutorial.cxx:6:10: fatal error: TutorialConfig.h: No such file or directory
6 | #include "TutorialConfig.h"
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
Build finished with error(s).
* The terminal process terminated with exit code: -1.
* Terminal will be reused by tasks, press any key to close it.