# Building CUDA (nvcc) code in UE4 Build System

**URL:** <https://forums.unrealengine.com/t/building-cuda-nvcc-code-in-ue4-build-system/438715>\
**Category:** Pipeline & Plugins\
**Tags:** build, buildcs, unreal-engine, Visual-Studio, UE4, CPP, question\
**Created:** [December 2, 2018, 6:16pm UTC](https://forums.unrealengine.com/t/building-cuda-nvcc-code-in-ue4-build-system/438715 "2018-12-02T18:16:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_13399bb2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_13399bb2](https://forums.unrealengine.com/u/anonymous_user_13399bb2)\
**Post date:** [December 2, 2018, 6:16pm UTC](https://forums.unrealengine.com/t/building-cuda-nvcc-code-in-ue4-build-system/438715/1 "2018-12-02T18:16:10Z")

</div>

Hi, so I have had no trouble building cuda static libraries in separate projects and then copying over the static library and headers into UE4 project and then linking it up. The directions in this link worked no problem: [http://www.sciement.com/tech-blog/c/cuda\_in\_ue4/](http://www.sciement.com/tech-blog/c/cuda_in_ue4/) (google translate)

Now I would like to instead include my cuda code directly into my plugin and build it with the rest of the system. I tried naively adding my code and adding the cuda build customizations to my project and flagging the CU kernel file as using cuda.

This results in several errors. Typical linking errors to unresolved symbols in the cuda object. Trying to clean results in new errors as well related to cuda.

I am sure my naive approach is missing much considering ue’s build ecosystem. I am still learning the UE4 build system and any guidance would be appreciated. If I was in linux I could just script around this having decades of experience there but for Windows I feel woefully inadequate.

Ultimately, I am trying to avoid needing to open two separate .sln files and have two separate VS instances running when working, then having to build and copy the separate cuda static lib and headers. Instead I want to have one VS instance, click one build button and not manually copy things. Any guidance would be much appreciated.

I am guessing this is going to have to do with Build.cs, anyway to use the nvcc compiler for the cu file or something?

I looked at:

> **[Pre/Post build step in UBT](https://forums.unrealengine.com/questions/411431/prepost-build-step-in-ubt.html)**
>
> The question is simple: how to set up a Pre build event and a post build event properly as the Unreal devs intend to? The current method I am using is not intended to be used like this, however pre/post/clean build steps are a very essential part of...

> **[Build cuda files for plugin (using UBT)](https://forums.unrealengine.com/questions/844018/view.html)**
>
> Hey, I’m planning to use cuda in one of my plugins. If I prebuild a static lib I already can use the cuda methods. In the next step I want to compile the cuda .cu files while (re-)building the plugin. For this I need to change the compiler to nvcc...

but don’t completely understand all this yet. Also, the whole can’t add nvcc or cuda tags due to reputation is annoying.

Edit: Adding another thought here. Could I take my standalone vs project that is creating the static libraries currently and somehow import this into my UE4 project, then add like some pre-build instructions to compile and use this project?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_13399bb2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_13399bb2](https://forums.unrealengine.com/u/anonymous_user_13399bb2)\
**Post date:** [February 23, 2019, 5:33pm UTC](https://forums.unrealengine.com/t/building-cuda-nvcc-code-in-ue4-build-system/438715/2 "2019-02-23T17:33:22Z")

</div>

I solved this ages ago for myself so I might as well post the answer. What I did in the end which worked a treat was create a project for my cuda code inside of the main UE4 solution I was working in. This project used the cuda compiler etc and compiled the libraries to some place relevant in my greater UE4 solution. I compiled the libraries and added them to my version control for convenience.

Then if someone else cloned my code, IF, they wanted to edit the cuda code all they needed to do was add the project.
