CUDA C++ problems with CMake on CLion IDE


I'm trying to start a project with CUDA C++ using CLion as an IDE. I installed a fresh version of CUDA Developer Tools (v10.2) and tried to load the changes of the MakeFile. Apparently, the CUDA compiler (nvcc) doesn't get properly linked, but I'm not sure this is the problem.

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)
project(test_cuda LANGUAGES CXX CUDA)



The result I get is the following:

"E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" <path_to_project>\test_cuda
-- The CUDA compiler identification is NVIDIA 10.2.89
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe -- broken
CMake Error at E:/Program Files/JetBrains/CLion 2019.2.5/bin/cmake/win/share/cmake-3.15/Modules/CMakeTestCUDACompiler.cmake:46 (message):
  The CUDA compiler

    "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/bin/nvcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: <path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeTmp

    Run Build Command(s):nmake /nologo cmTC_5cf15\fast &&   "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe" -f CMakeFiles\cmTC_5cf15.dir\build.make /nologo -L                  CMakeFiles\cmTC_5cf15.dir\build
    Building CUDA object CMakeFiles/cmTC_5cf15.dir/
        C:\PROGRA~1\NVIDIA~2\CUDA\v10.2\bin\nvcc.exe    -D_WINDOWS -Xcompiler=" /GR /EHsc"  -Xcompiler="-Zi -Ob0 -Od /RTC1" -Xcompiler=-MDd -x cu -c <path_to_project>\test_cuda\cmake-build-debug-visual-studio\CMakeFiles\CMakeTmp\ -o CMakeFiles\cmTC_5cf15.dir\ -Xcompiler=-FdCMakeFiles\cmTC_5cf15.dir\,-FS
    Linking CUDA executable cmTC_5cf15.exe
        "E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_5cf15.dir --rc=C:\PROGRA~2\WI3CF2~1\8.1\bin\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\8.1\bin\x86\mt.exe --manifests  -- C:\PROGRA~2\MICROS~1.0\VC\bin\link.exe /nologo "CMakeFiles\cmTC_5cf15.dir\"  @<path_to_appdata>\Local\Temp\nm8647.tmp
    LINK Pass 1: command "C:\PROGRA~2\MICROS~1.0\VC\bin\link.exe /nologo CMakeFiles\cmTC_5cf15.dir\ /out:cmTC_5cf15.exe /implib:cmTC_5cf15.lib /pdb:<path_to_project>\test_cuda\cmake-build-debug-visual-studio\CMakeFiles\CMakeTmp\cmTC_5cf15.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib/x64 cudadevrt.lib cudart_static.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_5cf15.dir/intermediate.manifest CMakeFiles\cmTC_5cf15.dir/manifest.res" failed (exit code 1112) with the following output:
    CMakeFiles\cmTC_5cf15.dir\ : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
    NMAKE : fatal error U1077: '"E:\Program Files\JetBrains\CLion 2019.2.5\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred!
See also "<path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeOutput.log".
See also "<path_to_project>/test_cuda/cmake-build-debug-visual-studio/CMakeFiles/CMakeError.log".

Where I substitute the path to the project folder with <path_to_project>.

The .cu file is just a simple hello world source file for now, since I'm trying to solve the issue with the CUDA compiler first.

I can't really find any way to solve this.

Thank you a lot in advance.

asked on Stack Overflow Jan 22, 2020 by Matteo Amatori • edited Jan 22, 2020 by talonmies

1 Answer


The message module machine type 'x64' conflicts with target machine type 'X86' is the crux of the problem. This indicates you have a 32-bit vs 64-bit architecture mismatch. Please be sure you use consistent project and compiler settings.

So, if you are compiling for a 64-bit architecture, make sure your project (CMake) settings are configured to build x64 targets. Also, you must be sure to use the 64-bit versions of the compilation tools (nvcc). Specifically for your case, your linker flags appear to contain /machine:X86, which would need to be removed if you are aiming for a 64-bit build. This can likely be configured through the CLion IDE in your Toolchain settings.

answered on Stack Overflow Jan 22, 2020 by squareskittles

User contributions licensed under CC BY-SA 3.0