我试图使用CMake和Visual Studio 2017编译CUDA项目, 但构建失败,详情如下。
系统
Windows 10 Pro x64
Visual Studio Enterprise 2017版本15.3.2
CUDA 9 RC(版本9.0.103)
CMake 3.9.1(生成器:Visual Studio 15 2017 Win64)
虚拟项目:
的CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(vs17cuda)
# Cuda is always required
find_package(CUDA REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11" )
add_subdirectory(src)
的src /的CMakeLists.txt
cuda_add_executable(vs17cuda main.cu)
set_target_properties(vs17cuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(vs17cuda ${CUDA_LIBRARIES})
的src / main.cu
#include <cuda_runtime.h>
__global__ void DummyKernel()
{
//do nothing
}
int main (int argc, char * argv[]) {
DummyKernel<<<4, 4>>>();
}
控制台输出:(德语消息翻译成英文)
1>------ Build started: Project: vs17cuda, Configuration: Debug x64 ------
1>Building NVCC (Device) object src/CMakeFiles/vs17cuda.dir/Debug/vs17cuda_generated_main.cu.obj
1>Failed to run C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/bin/cl.exe (File not found).
1>
1>).
1>CMake Error at vs17cuda_generated_main.cu.obj.Debug.cmake:222 (message):
1> Error generating
1> C:/Users/Sebastian/Documents/C++/vs17cuda/build/src/CMakeFiles/vs17cuda.dir//Debug/vs17cuda_generated_main.cu.obj
1>
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1.
1>Done building project "vs17cuda.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
如何修复构建?
答案 0 :(得分:1)
似乎CUDA现在与CMake完全集成。 FindCUDA包中的函数(例如cuda_add_executable
)现在恢复为默认add_executable
。有关详细信息,请参阅NVIDIA最近的一篇博文:here。我克隆了那篇文章中链接的Github回购邮件,它对我有用;虽然仅用于64位版本。