# Error when linking a shared library on Windows using Clang, CUDA and Ninja

**URL:** https://discourse.cmake.org/t/error-when-linking-a-shared-library-on-windows-using-clang-cuda-and-ninja/6377
**Category:** Code
**Tags:** os:windows, comp:clang, gen:ninja, lang:cuda
**Created:** [August 31, 2022, 1:43pm UTC](https://discourse.cmake.org/t/error-when-linking-a-shared-library-on-windows-using-clang-cuda-and-ninja/6377 "2022-08-31T13:43:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![harrytodorov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/harrytodorov/32/2726_2.png) [@harrytodorov](https://discourse.cmake.org/u/harrytodorov)
#### Post date: [August 31, 2022, 1:43pm UTC](https://discourse.cmake.org/t/error-when-linking-a-shared-library-on-windows-using-clang-cuda-and-ninja/6377/1 "2022-08-31T13:43:04Z")

</div>

I have recently worked on integrating `CUDA` in a project and have stumbled upon a couple of problems on Windows in combination with `Clang` (using the GNU-like command-line) and `Ninja`.

To demonstrate the problems there is a sample GitHub repository [cmake\_export\_all\_symbols](https://github.com/harrytodorov/cmake-windows-clang-issues).

There are two problems which occur - both are in the linking phase.

1. The LLVM linker `lld-link.exe` cannot find the library include path for CUDA, and produces the following two error messages:

```auto
clang++: error: no such file or directory: 'cudadevrt.lib'
clang++: error: no such file or directory: 'cudart_static.lib'

```

1. The `WINDOWS_EXPORT_ALL_SYMBOLS` property produces a `exports.def` (in `CMakeFiles\lib.dir\.\exports.def`) file, but it cannot be consumed by the linker. This seems to be somehow caused after `enable_language(CUDA)` call or when `CUDA` is one of the languages listed in the CMake `project`.

```auto
clang++: error: no such file or directory: '/DEF:CMakeFiles\lib.dir\.\exports.def'

```

The repository listed above works all fine when one changes `Clang` for `MSVC`.

Regarding the exact versions of the tools used:

- `CMake 3.23.2`
- `Clang 13.0.0`
- `CUDA 11.7`
- `Ninja 1.10.2`

I wanted to ask, whether these are known problems (as I couldn’t find any information here and in the issue tracker) and if there are ways to cleanly mitigate those problems.

So far, my teammates and I have found a workaround:

1. The first one we solved was by placing the missing `.lib` files in the corresponding build directory in a pre-link step.
2. Here we were lucky because all of our targets which use `WINDOWS_EXPORT_ALL_SYMBOLS` are independent of all our targets, which use `CUDA`. So we made sure that all targets using `WINDOWS_EXPORT_ALL_SYMBOLS` are compiled and linked before any `enable_language(CUDA)` call is encountered.

Thank you!

---

<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: [August 31, 2022, 6:04pm UTC](https://discourse.cmake.org/t/error-when-linking-a-shared-library-on-windows-using-clang-cuda-and-ninja/6377/2 "2022-08-31T18:04:10Z")

</div>

Cc: @robert.maynard

---

<div class="post-metadata">

### Author: ![onurulgen](https://discourse.cmake.org/user_avatar/discourse.cmake.org/onurulgen/32/4541_2.png) [@onurulgen](https://discourse.cmake.org/u/onurulgen)
#### Post date: [April 30, 2024, 3:38pm UTC](https://discourse.cmake.org/t/error-when-linking-a-shared-library-on-windows-using-clang-cuda-and-ninja/6377/3 "2024-04-30T15:38:02Z")

</div>

Hey guys, this is still a problem with CMake 3.28! I’m working on [NiftyReg project](https://github.com/KCL-BMEIS/niftyreg/tree/rearchitect-and-reinstate-gpu), and it compiles without any problem when I do it with clang-cl. However, it fails if it’s done with clang.
