为什么VS2019 Pro在通过CMake创建CUDA项目时会出现xutility、xmemory和atomic的编译错误? [英] Why does VS2019 Pro have compile errors with xutility, xmemory, and atomic when creating a CUDA project via CMake?

查看:69
本文介绍了为什么VS2019 Pro在通过CMake创建CUDA项目时会出现xutility、xmemory和atomic的编译错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 CMake 创建一个简单的 CUDA 项目,但遇到了奇怪的编译错误.我正在关注本教程.最初,我使用的是 Visual Studio 2019 Community、CMake 3.18.3 和 CUDA 11.3,一切正常.然后,我更新到 Visual Studio 2019 Professional 和 CMake 3.20.3,它无法编译完全相同的源代码.

I'm trying to create a simple CUDA project via CMake and getting strange compilation errors. I'm following this tutorial. Originally, I was using Visual Studio 2019 Community, CMake 3.18.3, and CUDA 11.3 and everything worked fine. Then, I updated to Visual Studio 2019 Professional and CMake 3.20.3, and it failed to compile the same exact same source code.

这是我的整个 CMakeLists 文件:

Here's my entire CMakeLists file:

cmake_minimum_required(VERSION 3.18.3)

project(hello_world LANGUAGES CXX CUDA)

add_executable(hello_world_target main.cu)

target_compile_features(hello_world_target PUBLIC cxx_std_11)
set_target_properties(hello_world_target PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(hello_world_target PROPERTIES CUDA_ARCHITECTURES "52")

这是我唯一的源文件 main.cu:

Here's my only source file, main.cu:

#include <iostream>

int main(){
  std::cout << "Hello, world!" << std::endl;
  return 0;
}

当我尝试编译时,出现以下错误:

When I try to compile, I get the following errors:

1>Compiling CUDA source file ..\main.cu...
1>
1>C:\Users\[username]\Documents\hello_cmake\build>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\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.30037\bin\HostX64\x64" -x cu -rdc=true   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\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"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /Od /Fdhello_world_target.dir\Debug\vc142.pdb /FS /Zi /RTC1 /MDd /GR" -o hello_world_target.dir\Debug\main.obj "C:\Users\[username]\Documents\hello_cmake\main.cu"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1>          detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=const char *, _Sentinel=const char *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(1990): here
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1>          detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=__wchar_t *, _Sentinel=__wchar_t *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(1991): here
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xutility(1309): error : expected a "("
1>          detected during instantiation of "void std::_Adl_verify_range(const _Iter &, const _Sentinel &) [with _Iter=const __wchar_t *, _Sentinel=const __wchar_t *]"
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30037\include\xlocale(2026): here

.....etc., etc., etc.....

31 errors detected in the compilation of "C:/Users/[username]/Documents/hello_cmake/main.cu".
1>main.cu
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 11.3.targets(785,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\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.30037\bin\HostX64\x64" -x cu -rdc=true   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\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"CMAKE_INTDIR=\"Debug\"" -D_MBCS -Xcompiler "/EHsc /W1 /nologo /Od /Fdhello_world_target.dir\Debug\vc142.pdb /FS /Zi /RTC1 /MDd /GR" -o hello_world_target.dir\Debug\main.obj "C:\Users\[username]\Documents\hello_cmake\main.cu"" exited with code 1.
1>Done building project "hello_world_target.vcxproj" -- FAILED.

令人困惑的是,这适用于不同版本的 Visual Studio 和 CMake.另外,如果我重写 CMakeLists.txt 文件以从 LANGUAGES 列表中删除 CUDA,并将 main.cu 更改为 main.cpp,一切正常.

What's perplexing is that this worked fine with the different versions of Visual Studio and CMake. Also, if I rewrite the CMakeLists.txt file to remove CUDA from the LANGUAGES list, and change main.cu to main.cpp, everything works fine.

编译器会抱怨 xutility、xmemory 和 atomic 文件也令人困惑.不过,这听起来像一条红鲱鱼.

It's also confusing that the compiler would complain about the xutility, xmemory, and atomic files. That sounds like a red herring, though.

可能导致此问题的原因是什么?

What could be causing this issue?

推荐答案

从 Visual Studio 2019 16.9.6 升级到 16.10 后,我遇到了基本相同的问题.该问题似乎是由 Visual Studio 2019 16.10 随附的 MSVC v142 构建工具 14.29.30037 版本中 xutility、xmemory 等的更改引起的.

I ran into basically the same problem after upgrading from Visual Studio 2019 16.9.6 to 16.10. The problem seems to be caused by changes in xutility, xmemory etc. in the version of the MSVC v142 build tools 14.29.30037 delivered with Visual Studio 2019 16.10.

我无法解决新版本构建工具的问题,但我找到了解决方法.可以从 VS2019 16.10 和 VS2019 16.10 安装 v142 构建工具:

I could not solve the problem for the new version of the build tools, but I found a workaround. It is possible to install the v142 build tools from VS2019 16.9 with VS2019 16.10:

在 VS 安装程序中,Visual Studio 2019->修改->单个组件"添加

In VS the installer, "Visual Studio 2019->Modify->Individual components" add

  • MSVC v142 - VS2019 C++ x64/x86 构建工具 (14.28-16.9)
  • 适用于 v142 构建工具(x86 和 x64)的 C++ v14.28 (16.9) ATL
  • 可选:MFC、命令行工具等.

要编译 CUDA CMake 项目,需要明确设置 MSVC 工具集版本.这可以通过输入

To compile the CUDA CMake project the MSVC toolset version needs to be set explicitly. This can be done by entering

version=14.28.29910

在 CMake GUI 中要使用的可选工具集(参数为 -T)(需要删除 CMake 缓存).

in "Optional toolset to use (argument to -T) in the CMake GUI (CMake cache needs to be deleted).

这篇关于为什么VS2019 Pro在通过CMake创建CUDA项目时会出现xutility、xmemory和atomic的编译错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆