NVCC 无法处理 MSVC 编译器选项中的嵌套引号
Posted
技术标签:
【中文标题】NVCC 无法处理 MSVC 编译器选项中的嵌套引号【英文标题】:NVCC can't handle nested quotes in MSVC compiler options 【发布时间】:2021-12-08 06:25:44 【问题描述】:我正在使用以下配置:CUDA 11.4、CMake 3.21.3、Visual Studio 16.11.5、Windows 10。
我已经使用 CMake 成功生成了 VS2019 解决方案。这是完整的 CMakeLists.txt 文件 (also found here):
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(cmake_and_cuda LANGUAGES CXX CUDA)
include(CTest)
add_library(particles STATIC
randomize.cpp
randomize.h
particle.cu
particle.h
v3.cu
v3.h
)
# Request that particles be built with -std=c++11
# As this is a public compile feature anything that links to particles
# will also build with -std=c++11
target_compile_features(particles PUBLIC cxx_std_11)
# We need to explicitly state that we need all CUDA files in the particle
# library to be built with -dc as the member functions could be called by
# other libraries and executables
set_target_properties( particles
PROPERTIES CUDA_SEPARABLE_COMPILATION ON
)
if(BUILD_TESTING)
add_executable(particle_test test.cu)
set_target_properties(particle_test PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(particle_test PRIVATE particles)
add_test(NAME particles_10k COMMAND particle_test 10000 )
add_test(NAME particles_256k COMMAND particle_test 256000 )
if(APPLE)
# We need to add the default path to the driver (libcuda.dylib) as an rpath,
# so that the static cuda runtime can find it at runtime.
set_property(TARGET particle_test PROPERTY BUILD_RPATH $CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES)
endif()
endif()
当我尝试构建解决方案时,它失败了。查看输出,我收到以下错误:nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
。这是它尝试运行的 nvcc 命令之一:
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\bin\nvcc.exe"
-gencode=arch=compute_52,code=\"compute_52,compute_52\"
-gencode=arch=compute_52,code=\"sm_52,compute_52\"
--use-local-env
-ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64"
-x cu
-rdc=true
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\include"
--keep-dir x64\Debug
-maxrregcount=0
--machine 64
--compile
-cudart static
-std=c++14
-Xcompiler="/EHsc -Zi -Ob0" -g -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\""
-D_MBCS -DWIN32 -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\""
-Xcompiler "/EHsc /W3 /nologo /Od /Fd"C:\Users\firstname lastname\Documents\Github\code-samples\posts\cmake\build\Debug\particles.pdb" /FS /Zi /RTC1 /MDd /GR"
-o particles.dir\Debug\particle.obj
"C:\Users\firstname lastname\Documents\Github\code-samples\posts\cmake\particle.cu"
我不太清楚,但我认为第二个 -Xcompiler
选项中的嵌套引号很难处理。
CMakeLists.txt 文件有什么问题吗?这个 nvcc 命令看起来对吗?为什么 nvcc 认为我试图给它多个输入文件?
【问题讨论】:
forums.developer.nvidia.com/t/… 【参考方案1】:所以,看起来这是 OP 现在提交的 CMake 错误:问题 22786。
【讨论】:
以上是关于NVCC 无法处理 MSVC 编译器选项中的嵌套引号的主要内容,如果未能解决你的问题,请参考以下文章