# OpenACC + CUDA + CMake

**URL:** https://discourse.cmake.org/t/openacc-cuda-cmake/9317
**Category:** Code
**Tags:** lang:cuda
**Created:** [October 31, 2023, 8:38am UTC](https://discourse.cmake.org/t/openacc-cuda-cmake/9317 "2023-10-31T08:38:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mihaly\_sisak\_conti](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/5fc32e/32.png) [@mihaly\_sisak\_conti](https://discourse.cmake.org/u/mihaly_sisak_conti)
#### Post date: [October 31, 2023, 8:38am UTC](https://discourse.cmake.org/t/openacc-cuda-cmake/9317/1 "2023-10-31T08:38:00Z")

</div>

New users can not upload attachements, so I linked them here:  
[https://forums.developer.nvidia.com/t/openacc-cuda-interop-with-cmake/270794/4?u=janos.mihaly.sisak](https://forums.developer.nvidia.com/t/openacc-cuda-interop-with-cmake/270794/4?u=janos.mihaly.sisak)

We would like to use C with OpenACC pragmas and CUDA kernels in some hotspots.  
With make everything is fine. However we would like to build with CMake.  
We started with this repo:  
[https://github.com/jefflarkin/openacc-interoperability](https://github.com/jefflarkin/openacc-interoperability)  
We needed to remove \<LINK\_LIBRARIES\> from CMAKE\_CUDA\_LINK\_EXECUTABLE because it tries to link cuda libraries in the nvc++ link step, causing errors at runtime. This way however we can not link external libraries, which we want to do.

The CMake line with added LINK\_LIBRARIES:

```auto
set(CMAKE_CUDA_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")

```

It would be preferable to have an elegant solution work, without the cmake list mangling for example. Is it possible?

---

<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: [November 2, 2023, 9:16pm UTC](https://discourse.cmake.org/t/openacc-cuda-cmake/9317/2 "2023-11-02T21:16:38Z")

</div>

Cc: @robert.maynard
