# "TutorialConfig.h: No such file or directory"

**URL:** <https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [July 17, 2023, 2:11pm UTC](https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535 "2023-07-17T14:11:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaafar-omar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jaafar-omar/32/3614_2.png) [@jaafar-omar](https://discourse.cmake.org/u/jaafar-omar)\
**Post date:** [July 17, 2023, 2:11pm UTC](https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535/1 "2023-07-17T14:11:33Z")

</div>

**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:**

```auto
# 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:**

```auto
// 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:**

```auto
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. 

```

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [July 17, 2023, 6:36pm UTC](https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535/2 "2023-07-17T18:36:06Z")

</div>

That line:

```cmake
configure_file(TutorialConfig.h.in TutorialConfig.h)

```

means that there a file `TutorialConfig.h.in` (_a kind of a “template”_) in the project folder, which CMake will “configure” into a final `TutorialConfig.h`. You said that “_TutorialConfig.h file is inside the Step1\_build directory_”, so probably for some reason `${PROJECT_BINARY_DIR}` points to a different path, because this line:

```cmake
target_include_directories(Tutorial PUBLIC "${PROJECT_BINARY_DIR}")

```

says that this is where headers live, and if `${PROJECT_BINARY_DIR}` path was the same as your “_Step1\_build directory_”, then it should have worked, so apparently it isn’t.

It could be also that the tutorial you are using (_you haven’t provided a link to it_) isn’t correct, because I’d expect header configuration to look like this:

```cmake
configure_file(TutorialConfig.h.in "${PROJECT_BINARY_DIR}/TutorialConfig.h")

```

and as a matter of fact, [this project](https://github.com/mbbill/CMake-Tutorial/blob/master/Step1/CMakeLists.txt#L10) does (_almost_) exactly that.

---

<div class="post-metadata">

**Author:** ![jaafar-omar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jaafar-omar/32/3614_2.png) [@jaafar-omar](https://discourse.cmake.org/u/jaafar-omar)\
**Post date:** [July 18, 2023, 3:11am UTC](https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535/3 "2023-07-18T03:11:22Z")

</div>

But the tricky part is when I type the “#include \<TutorialConfig.h\>” manually it can detect by the intellisense (I’m using VS Code).

Where should I put the Step1\_build in my directory? so I have this directory structure:

```auto
├── CMAKE-3.27.0-RCSTUTORIAL-SOURCE
├── Step1
├── Step2
├── Step3
├── Step4
└── Step5

```

Should I put the Step1\_build in this:

```auto
├── CMAKE-3.27.0-RCSTUTORIAL-SOURCE
└── Step1\
   ├── Step1_build
   ├── CMakeLists.txt
   ├── tutorial.cxx
   ├── TutorialConfig.h.in
├── Step2
├── Step3
├── Step4
└── Step5

```

Or like this (this is my directory structure right now):

```auto
├── CMAKE-3.27.0-RCSTUTORIAL-SOURCE
├── Step1
├── Step1_build
├── Step2
├── Step3
├── Step4
└── Step5

```

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [July 18, 2023, 8:11am UTC](https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535/4 "2023-07-18T08:11:06Z")

</div>

The part about IntelliSense I didn’t get, but that doesn’t matter that much anyway.

If every `Step*` folder is a CMake project, then I would put build folders as subfolders of those, like in your first option. You also didn’t show how exactly you are running CMake configuration and build: from which folder and with what parameters.

I also see that now you did `<TutorialConfig.h>`, while in the first post it is `"TutorialConfig.h"`. This can also make a difference.

---

<div class="post-metadata">

**Author:** ![jaafar-omar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jaafar-omar/32/3614_2.png) [@jaafar-omar](https://discourse.cmake.org/u/jaafar-omar)\
**Post date:** [July 18, 2023, 8:53am UTC](https://discourse.cmake.org/t/tutorialconfig-h-no-such-file-or-directory/8535/5 "2023-07-18T08:53:45Z")

</div>

Hey, thank you for the patient. I think I figure it out where the root of the problem. I do the cmake and build in the terminal using `cmake ../` and `make` , but I’m using vs code which uses ninja as build. When I try to run the executable file in the terminal, it execute without error, but when I run the executable by clicking the run button in vc code IDE it errors saying no such file. I think the problem is in the IDE or C/C++ and CMake Tools extension.
