Program execution fails when CUDA is added

  • OS: windows 10
  • CUDA version: 11.5 
  • CLion version: 2023.3.1 
  • Build System: CMake

For the last few months, I have been working on a C++ and CUDA project. Everything was fine till tomorrow when my project all of a sudden broke down and I got a strange error related to CUDA. After failing for many times, I wanted to see if a plain CUDA project works on my CLion. But strangely enough, I get the same error in a very simple and basic c++project. If I remove CUDA from the second line, the program will execute.
As you can see in the following image, I have only added CUDA to the project line of CMake, but still it fails:

Here is the CMake configuration of the project : 


Here is the entire log of the project after failing:

====================[ Build | untitled9 | Debug-Visual Studio ]=================
"C:\Program Files\JetBrains\CLion 2023.2.2\bin\cmake\win\x64\bin\cmake.exe" --build "C:\Users\SMS BY KEYTECH\CLionProjects\untitled9\cmake-build-debug-visual-studio" --target untitled9 --config Debug
CMake is re-running because C:/Users/SMS BY KEYTECH/CLionProjects/untitled9/cmake-build-debug-visual-studio/CMakeFiles/generate.stamp is out-of-date.
 the file 'C:/Users/SMS BY KEYTECH/CLionProjects/untitled9/CMakeLists.txt'
 is newer than 'C:/Users/SMS BY KEYTECH/CLionProjects/untitled9/cmake-build-debug-visual-studio/CMakeFiles/generate.stamp.depend'
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
CMake Error at C:/Program Files/JetBrains/CLion 2023.2.2/bin/cmake/win/x64/share/cmake-3.27/Modules/CMakeDetermineCompilerId.cmake:756 (message):
 Compiling the CUDA compiler identification source file
 "" failed.


 Build flags:

 Id flags: --keep;--keep-dir;tmp -v


 The output was:


 Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework

 Copyright (C) Microsoft Corporation.  All rights reserved.


 Build started 14/12/2023 11:42:19.

 Project "C:\Users\SMS BY
 on node 1 (default targets).


   Creating directory "Debug\".
   Creating directory "Debug\CompilerIdCUDA.tlog\".


   Creating "Debug\CompilerIdCUDA.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.


   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /E /nologo /showIncludes /TP /D__CUDACC__ /D_MBCS /I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include" /I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\bin" /I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include" /I. /FIcuda_runtime.h /c "C:\Users\SMS BY KEYTECH\CLionProjects\untitled9\cmake-build-debug-visual-studio\CMakeFiles\3.27.0\CompilerIdCUDA\"

 Project "C:\Users\SMS BY
 (1) is building "C:\Users\SMS BY
 (1:2) on node 1 (CudaBuildCore target(s)).


   Compiling CUDA source file

 C:\Program Files (x86)\Microsoft Visual
 11.5.targets(785,9): error MSB4175: The task factory "XamlTaskFactory"
 could not be loaded from the assembly "Microsoft.Build.Tasks.v4.0,
 Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".  Cannot
 execute a program.  The command being executed was
 "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /noconfig
 /fullpaths @"C:\Users\SMS BY KEYTECH\AppData\Local\Temp\qkqo4vpi.cmdline".
 [C:\Users\SMS BY

 Done Building Project "C:\Users\SMS BY
 (CudaBuildCore target(s)) -- FAILED.

 Done Building Project "C:\Users\SMS BY
 (default targets) -- FAILED.


 Build FAILED.


 "C:\Users\SMS BY
 (default target) (1) ->

 "C:\Users\SMS BY
 (CudaBuildCore target) (1:2) ->

 (CudaBuildCore target) ->

   C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 11.5.targets(785,9): error MSB4175: The task factory "XamlTaskFactory" could not be loaded from the assembly "Microsoft.Build.Tasks.v4.0, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Cannot execute a program. The command being executed was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /noconfig /fullpaths @"C:\Users\SMS BY KEYTECH\AppData\Local\Temp\qkqo4vpi.cmdline". [C:\Users\SMS BY KEYTECH\CLionProjects\untitled9\cmake-build-debug-visual-studio\CMakeFiles\3.27.0\CompilerIdCUDA\CompilerIdCUDA.vcxproj]


     0 Warning(s)
     1 Error(s)


 Time Elapsed 00:00:01.49



Call Stack (most recent call first):
 C:/Program Files/JetBrains/CLion 2023.2.2/bin/cmake/win/x64/share/cmake-3.27/Modules/CMakeDetermineCompilerId.cmake:8 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
 C:/Program Files/JetBrains/CLion 2023.2.2/bin/cmake/win/x64/share/cmake-3.27/Modules/CMakeDetermineCompilerId.cmake:53 (__determine_compiler_id_test)
 C:/Program Files/JetBrains/CLion 2023.2.2/bin/cmake/win/x64/share/cmake-3.27/Modules/CMakeDetermineCUDACompiler.cmake:307 (CMAKE_DETERMINE_COMPILER_ID)
 CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!
CMake Configure step failed.  Build files cannot be regenerated correctly.



Please do the following:

  1. Change the project() command in your CMakeLists.txt in the following way: project(untitled9 LANGUAGES CUDA CXX).
  2. Make sure that amd64 is selected in the “Architecture” field of your MSVC toolchain in `File | Settings | Build, Execution, Deployment | Toolchains`.
  3. Remove -G "Visual Studio 15 2017" -A x64 from the “CMake options” field of your CMake profile.
  4. Set up the CUDA compiler by setting the CMAKE_CUDA_COMPILER variable to the location of the NVCC executable (see the second point here).
  5. Do `Tools | CMake | Reset Cache and Reload Project`.

Do you get any warnings/errors in the CMake tool window? Does the project build successfully after these changes?


Thanks for  sharing this.


Please sign in to leave a comment.