# Link error when building Gromacs on windows with CUDA

**URL:** <https://gromacs.bioexcel.eu/t/link-error-when-building-gromacs-on-windows-with-cuda/5277>\
**Category:** User discussions\
**Tags:** installation-error\
**Created:** [November 18, 2022, 5:00pm UTC](https://gromacs.bioexcel.eu/t/link-error-when-building-gromacs-on-windows-with-cuda/5277 "2022-11-18T17:00:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Supernova](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/supernova/32/1400_2.png) [@Supernova](https://gromacs.bioexcel.eu/u/Supernova)\
**Post date:** [November 18, 2022, 5:00pm UTC](https://gromacs.bioexcel.eu/t/link-error-when-building-gromacs-on-windows-with-cuda/5277/1 "2022-11-18T17:00:27Z")

</div>

GROMACS version: 2022.4  
GROMACS modification: Yes(Minor)  
I tried to compile Gromacs 2022.4 on Win10 with Visual Studio 2022 Professional. When I set GMX\_GPU=NO, I compiled correctly. However, when I set GMX\_GPU=CUDA, VS showed multiple errors during compilation. I replaced CXX17 to CUDA17 in gmxManageNvccConfig.cmake and thus fixed the problem with -std:c++17. I also added error messages to `static_assert` functions so that these files could be compiled. I added `#include <tuple>` lines to some files to avoid undefined errors. Finally, no errors met during the second stage, but it encountered link error when generating `gromacs.lib`. I found that the error may come from different type of runtime between the source code (MT) and my project(MD), but I have changed all the C++ code generation rules to MT, and the problem still exists.  
Hope that someone could give me some solutions to solve this problem. Thank you!

---

<div class="post-metadata">

**Author:** ![SeLarin](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@SeLarin](https://gromacs.bioexcel.eu/u/SeLarin)\
**Post date:** [March 12, 2023, 1:01pm UTC](https://gromacs.bioexcel.eu/t/link-error-when-building-gromacs-on-windows-with-cuda/5277/2 "2023-03-12T13:01:01Z")

</div>

I had exactly same problem when it was not possible to link gmx with CUDA files due to LNK2038 error. It is due to CMake uses MultiThreadedDLL as RuntimeLibrary value by default and this behaviour do not depend on shared/static options provided by Gromacs setup.

It is possible to change this behaviour using CMAKE\_MSVC\_RUNTIME\_LIBRARY property introduced in CMake 3.15 ([CMAKE\_MSVC\_RUNTIME\_LIBRARY — CMake 3.26.0-rc6 Documentation](https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html#variable:CMAKE_MSVC_RUNTIME_LIBRARY)). I have used “MultiThreaded$\<$CONFIG:Debug:Debug\>” value and build was successful. Also, I switch off build of shared libraries and gmx and swith on using of static libraries where possible.
