How to enable C++17 code generation in VS2019 CUDA project

与世无争的帅哥 提交于 2021-01-29 06:55:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/63036624/how-to-enable-c17-code-generation-in-vs2019-cuda-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!