簡體   English   中英

CLion IDE 上 CMake 的 CUDA C++ 問題

[英]CUDA C++ problems with CMake on CLion IDE

我正在嘗試使用 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>替換項目文件夾的<path_to_project>

.cu 文件現在只是一個簡單的 hello world 源文件,因為我試圖首先用 CUDA 編譯器解決這個問題。

我真的找不到任何方法來解決這個問題。

非常感謝您提前。

消息module machine type 'x64' conflicts with target machine type 'X86'是問題的關鍵。 這表明您有 32 位與 64 位架構不匹配。 請確保您使用一致的項目和編譯器設置。

因此,如果您要針對 64 位架構進行編譯,請確保您的項目 (CMake) 設置已配置為構建 x64 目標。 此外,您必須確保使用 64 位版本的編譯工具 (nvcc)。 特別是對於您的情況,您的鏈接器標志似乎包含/machine:X86 ,如果您的目標是 64 位構建,則需要將其刪除。 這可能可以通過工具鏈設置中的 CLion IDE 進行配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM