CLion IDE上CMake的CUDA C ++问题

问题描述 投票:0回答:1

我正在尝试使用CLion作为IDE使用CUDA C ++启动项目。我安装了新版本的CUDA Developer Tools(v10.2),并尝试加载MakeFile的更改。显然,CUDA编译器(nvcc)无法正确链接,但是我不确定这是问题所在。

这是我的CMakeLists.txt:

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

set(CMAKE_CXX_STANDARD 17)

add_executable(test_cuda main.cu)

我得到的结果如下:

"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/main.cu.obj
        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\main.cu -o CMakeFiles\cmTC_5cf15.dir\main.cu.obj -Xcompiler=-FdCMakeFiles\cmTC_5cf15.dir\,-FS
    main.cu
    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\main.cu.obj"  @<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\main.cu.obj /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\main.cu.obj : 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'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\nmake.exe"' : return code '0x2'
    Stop.


  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".
[Finished]

<path_to_project>替换项目文件夹的路径。

。cu文件目前只是一个简单的hello world源文件,因为我首先尝试使用CUDA编译器解决问题。

我真的找不到解决此问题的任何方法。

非常感谢。

c++ makefile cmake cuda
1个回答
2
投票

消息module machine type 'x64' conflicts with target machine type 'X86'是问题的症结所在。这表明您有32位和64位体系结构不匹配。请确保使用consistent项目和编译器设置。

因此,如果要针对64位体系结构进行编译,请确保将项目(CMake)设置配置为构建x64目标。另外,您必须确保使用64位版本的编译工具(nvcc)。专门针对您的情况,您的链接器标志似乎包含/machine:X86,如果您打算使用64位构建,则需要将其删除。可以通过CLion IDE在您的[[Toolchain设置中进行配置。

© www.soinside.com 2019 - 2024. All rights reserved.