# \`generate\_export\_header\` + \`target\_include\_directories\` leaves \`fatal error C1083: Cannot open include file\`

**URL:** <https://discourse.cmake.org/t/generate-export-header-target-include-directories-leaves-fatal-error-c1083-cannot-open-include-file/3708>\
**Category:** Code\
**Created:** [July 7, 2021, 5:37pm UTC](https://discourse.cmake.org/t/generate-export-header-target-include-directories-leaves-fatal-error-c1083-cannot-open-include-file/3708 "2021-07-07T17:37:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamuelMarks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuelmarks/32/1619_2.png) [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)\
**Post date:** [July 7, 2021, 5:37pm UTC](https://discourse.cmake.org/t/generate-export-header-target-include-directories-leaves-fatal-error-c1083-cannot-open-include-file/3708/1 "2021-07-07T17:37:01Z")

</div>

I added these lines to my [cmake-example-with-vcpkg/versions/CMakeLists.txt at 993ec593d7b0f26dbd2c7eac3953a894081e69bd · SamuelMarks/cmake-example-with-vcpkg · GitHub](https://github.com/SamuelMarks/cmake-example-with-vcpkg/blob/993ec59/versions/CMakeLists.txt)

```cmake
# set(LIBRARY_NAME "versions")
include(GenerateExportHeader)

generate_export_header(
    "${LIBRARY_NAME}"
    EXPORT_FILE_NAME
    "${PROJECT_BINARY_DIR}/${LIBRARY_NAME}_export.h"
)

target_include_directories(
    "${LIBRARY_NAME}"
    INTERFACE # also tried `PUBLIC` and `PRIVATE`
    "${PROJECT_BINARY_DIR}"
)

```

```c
#include "versions_export.h"
/* also tried: #include <versions_export.h> */

```

But I’m left with this error:

> `versions\versions.h`(17): fatal error C1083: Cannot open include file: `'versions_export.h'`: No such file or directory

* * *

How do I setup the [`generate_export_header`](https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html) workflow correctly?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [July 7, 2021, 9:13pm UTC](https://discourse.cmake.org/t/generate-export-header-target-include-directories-leaves-fatal-error-c1083-cannot-open-include-file/3708/2 "2021-07-07T21:13:40Z")

</div>

Can you see `versions_export.h` in the build tree? I suspect that `EXPORT_FILE_NAME` is expecting just a filename, so you’re getting `/path/to/binary/dir/path/to/binary/dir/versions_export.h`.

---

<div class="post-metadata">

**Author:** ![SamuelMarks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuelmarks/32/1619_2.png) [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)\
**Post date:** [July 8, 2021, 12:17am UTC](https://discourse.cmake.org/t/generate-export-header-target-include-directories-leaves-fatal-error-c1083-cannot-open-include-file/3708/3 "2021-07-08T00:17:05Z")

</div>

`versions_export.h` appears in my build dir, and my IDE recognises it in the `#include`.

Relative paths work, as do absolute paths. But regardless when I got to actually build it I get this ‘not found’ error. Maybe it needs its own target so that it is guaranteed generated before it is used or something?

(My `CMakeLists.txt` is only 53 lines so if you know what it needs just try and see)

Thanks

---

<div class="post-metadata">

**Author:** ![SamuelMarks](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samuelmarks/32/1619_2.png) [@SamuelMarks](https://discourse.cmake.org/u/SamuelMarks)\
**Post date:** [July 8, 2021, 1:13pm UTC](https://discourse.cmake.org/t/generate-export-header-target-include-directories-leaves-fatal-error-c1083-cannot-open-include-file/3708/4 "2021-07-08T13:13:12Z")

</div>

Ended up cheating with:

```cmake
set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/${LIBRARY_NAME}_export.h")
generate_export_header("${LIBRARY_NAME}" EXPORT_FILE_NAME "${_export_file}")

```

> <https://github.com/SamuelMarks/cmake-example-with-vcpkg/commit/e4e99106b#diff-5f7f19002d021ab261d5dce92dd114f71e0ab6c7ecfbcad2a505fa4f78a2c6dd>

Unfortunately `${CMAKE_CURRENT_SOURCE_DIR}` was the only thing that worked. Tried everything from relative paths to `${CMAKE_CURRENT_BINARY_DIR}` to no `EXPORT_FILE_NAME` to completely different targets.
