如何在VS2019 CUDA项目中启用C ++ 17代码生成 [英] How to enable C++17 code generation in VS2019 CUDA project

查看:115
本文介绍了如何在VS2019 CUDA项目中启用C ++ 17代码生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将某些代码从一台PC上的VS2017迁移到另一台具有VS2019的PC上.一切都很好,除了我不能使用std :: filesystem.在我以前的代码中,我使用的是C ++ 14,并且具有std :: experimental :: filesystem.在新代码中,我想移至C ++ 17,所以我更改为std :: filesystem(如下面的代码所示).奇怪的是,智能感知(不确定它是否是事物的正确名称)没有显示错误.当我输入std :: f ...

时,它甚至显示文件系统

但是代码将不会生成,并给出错误命名空间" std".没有成员文件系统".

我将C ++语言标准更改为c ++ latest,VS2019版本是Community 16.6.5.

  #include< string>#include< iostream>#include< filesystem>命名空间fs = std :: filesystem;int main(){std :: string path ="C:\\";对于(const auto& entry:fs :: directory_iterator(path))std :: cout<<entry.path()<<std :: endl;} 

我最初的问题的最后一行可能还不够清楚:我已经更改了"C ++语言标准"到C ++ 17或C ++ latest.

根据要求,输出:

由于@drescherjm,我们发现这是一个Cuda问题.有Cuda专家有什么想法吗?

解决方案

使用CUDA 11, nvcc 编译器驱动程序能够支持

(这些说明可能会随CUDA的将来版本或Visual Studio的将来版本而改变.)

请注意,此方法仅适用于CUDA项目(即,当调用 nvcc 进行编译时),并且无论您的代码是否位于以 .cpp 或以 .cu 结尾的文件中.对于非CUDA项目,可能会有所帮助./p>

std :: filesystem 功能似乎需要C ++ 17.CUDA nvcc 编译器驱动程序已记录在这里.

I am moving some code from VS2017 on one pc to another pc with VS2019. Everything is fine excepted that I cannot use std::filesystem. In my former code, I was using C++14 and had std::experimental::filesystem. In the new code, I want to move to C++17 so I changed to std::filesystem (as shown in my code below). The weird thing is that intellisense (not sure it is the right name of the thing) shows no error. It even displays filesystem when I type std::f...

But the code won't build and give the error "namespace "std" has no member "filesystem"".

I changed C++ Language Standard to c++latest, VS2019 version is Community 16.6.5.

#include <string>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;

int main()
{
    std::string path = "C:\\";
    for (const auto& entry : fs::directory_iterator(path))
        std::cout << entry.path() << std::endl;
}

EDIT: The last line of my initial question might not have been clear enough: I already changed "C++ Language Standard" to C++17 or C++latest.

EDIT: As requested, the output:

Thanks to @drescherjm, we found that it is a Cuda issue. Any idea from a Cuda specialist?

解决方案

Using CUDA 11, the nvcc compiler-driver is capable of supporting usage of certain C++17 language features. Currently, in VS2019, this doesn't appear to be the default behavior.

The following method should work to enable C++17 support when compiling a cuda project in VS2019:

go to Project..Properties..Configuration Properties...CUDA C/C++...Command Line Then you will see a box in the right hand side bottom of the dialog labelled "Additional Options". In that box, type the following:

-std=c++17 -Xcompiler "/std:c++17"

then click "Apply" then rebuild.

(These instructions may change for future versions of CUDA or future versions of Visual Studio.)

Note that this method applies to CUDA projects only (i.e. when nvcc is invoked for compilation), and should be workable whether your code is in a file ending in .cpp or in a file ending in .cu. For non-CUDA projects, this may be helpful.

The std::filesystem features appear to require C++17. The CUDA nvcc compiler-driver is documented here.

这篇关于如何在VS2019 CUDA项目中启用C ++ 17代码生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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