# \`export(EXPORT)\` does not work for windows?

**URL:** <https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [February 15, 2024, 7:52pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109 "2024-02-15T19:52:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Post date:** [February 15, 2024, 7:52pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109/1 "2024-02-15T19:52:46Z")

</div>

I am using the build directory’s `...Config.cmake` file to test that the project works well with `find_package`. However, on windows this approach does not seem to work, giving me DLL\_IMPORT errors. I am not sure what to make of this. Looking at the generated file it looks like:

```cmake
add_library(Spglib::symspg SHARED IMPORTED)

set_target_properties(Spglib::symspg PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "D:/a/spglib/spglib/cmake-build-ci-windows/src"
)

# Import target "Spglib::symspg" for configuration "RelWithDebInfo"
set_property(TARGET Spglib::symspg APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
set_target_properties(Spglib::symspg PROPERTIES
  IMPORTED_IMPLIB_RELWITHDEBINFO "D:/a/spglib/spglib/cmake-build-ci-windows/lib/symspg.lib"
  IMPORTED_LOCATION_RELWITHDEBINFO "D:/a/spglib/spglib/cmake-build-ci-windows/bin/symspg.dll"
  )

```

Not sure how the install one is supposed to look like and what is responsible for populating `Path` in order for a test executable to be runable from there.

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [February 15, 2024, 8:29pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109/2 "2024-02-15T20:29:16Z")

</div>

### Whatever you want to do with this `cmake snipped`, is seems completly wrong to me!

Have a look at [ClausKlein/ModernCppStarter: 🚀 Kick-start your C++! A template for modern C++ projects using CMake, CI, code coverage, clang-format, reproducible dependency management and much more. (github.com)](https://github.com/ClausKlein/ModernCppStarter)

or [Professional CMake: A Practical Guide (crascit.com)](https://crascit.com/professional-cmake/)

---

<div class="post-metadata">

**Author:** ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Post date:** [February 15, 2024, 8:33pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109/3 "2024-02-15T20:33:19Z")

</div>

The snippet is the the snippet from the generated `Targets.cmake` file. The using snippet is the general use:

```cmake
find_package(Spglib REQUIRED)

add_executable(main_c src/main.c)
target_link_libraries(main_c PRIVATE Spglib::symspg)

```

I am looking into [this approach](https://stackoverflow.com/a/77990416) to more generally add the dll to targets.

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [February 15, 2024, 8:37pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109/4 "2024-02-15T20:37:06Z")

</div>

> [@Lecris](#):
>
> I am looking into [this approach](https://stackoverflow.com/a/77990416) to more generally add the dll to targets

This is **not** quite easy!  
see [CppCon 2019: Deep CMake For Library Authors - Crascit](https://crascit.com/2019/10/16/cppcon-2019-deep-cmake-for-library-authors/)

---

<div class="post-metadata">

**Author:** ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Post date:** [February 15, 2024, 8:47pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109/5 "2024-02-15T20:47:09Z")

</div>

> [@ClausKlein](#):
>
> This is **not** quite easy!  
> see [CppCon 2019: Deep CMake For Library Authors - Crascit](https://crascit.com/2019/10/16/cppcon-2019-deep-cmake-for-library-authors/)

Not sure what you mean by that link:

- I have opened a discussion about the design of [`GenerateExportHeader`](https://discourse.cmake.org/t/generateexportheader-and-multi-compiler-support/10102)
- Most of the contents I am already implementing. Currently working on [this](https://github.com/spglib/spglib/pull/437) if more context is helpful
- The issue here is more along the line of how `export(EXPORT)` creates the targets for build so that an executable can be run. Alex’s SO approach with `TARGET_RUNTIME_DLL_DIRS` is indeed very, although it is cumbersome to implement

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [February 16, 2024, 6:31pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109/6 "2024-02-16T18:31:41Z")

</div>

> [@Lecris](#):
>
> Most of the contents I am already implementing. Currently working on [this](https://github.com/spglib/spglib/pull/437) if more context is helpful

### YES, it is!

If have implemented it to today: [Use GenerateExportHeader by ClausKlein · Pull Request #1 · ClausKlein/spglib (github.com)](https://github.com/ClausKlein/spglib/pull/1)

---

<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:** [February 17, 2024, 4:59pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109/7 "2024-02-17T16:59:24Z")

</div>

I think these issues are along the lines of what you’re looking for:

- [https://gitlab.kitware.com/cmake/cmake/-/issues/25684](https://gitlab.kitware.com/cmake/cmake/-/issues/25684)
- [https://gitlab.kitware.com/cmake/cmake/-/issues/25686](https://gitlab.kitware.com/cmake/cmake/-/issues/25686)
- [https://gitlab.kitware.com/cmake/cmake/-/issues/24129](https://gitlab.kitware.com/cmake/cmake/-/issues/24129)

---

<div class="post-metadata">

**Author:** ![Lecris](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lecris/32/3193_2.png) [@Lecris](https://discourse.cmake.org/u/Lecris)\
**Post date:** [February 17, 2024, 5:19pm UTC](https://discourse.cmake.org/t/export-export-does-not-work-for-windows/10109/8 "2024-02-17T17:19:56Z")

</div>

Thanks Ben, indeed I have converged to a similar approach. It would be nice if `export(EXPORT)` were able to take care of that similar to RPATH, like populating `ENVIRONMENT_MODIFICATIONS `, but there is no mechanism for propagating properties like `INTERFACE`, so indeed I can’t see a way around it.
