在CMakeLists中组合C ++和CUDA时,将CXX-standard设置为c ++ 17 [英] Set CXX-standard to c++17 when combining C++ and CUDA in CMakeLists

查看:66
本文介绍了在CMakeLists中组合C ++和CUDA时,将CXX-standard设置为c ++ 17的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据CMake的文档,我只需要编写

According to the documentation of CMake I just have to write

project(${PROJECT_NAME} LANGUAGES CUDA CXX)

当我想在一个项目中组合CUDA文件和本机C ++文件时.然后,我不必再调用 cuda_add_executable(),而是调用 add_executable ,CMake应该自己弄清楚所有内容.除非我想为C ++代码指定标准(通过使用 set(CMAKE_CXX_STANDARD 17)),否则此方法工作正常.然后我收到错误消息

when I would like to combine CUDA-files and native C++-files in one project. Then I do not have to call cuda_add_executable() anymore, but rather add_executable, and CMake should figure out everything on its own. This works fine, unless I would like to specify a standard for C++-code (by using set(CMAKE_CXX_STANDARD 17)). Then I get the error message

Target requires the language dialect "CUDA17" (with compiler extensions), but CMake does not know the compile flags to use to enable it

是否有替代解决方案,还是应该恢复为 find_package(CUDA) cuda_add_executable ?

Is there an alternative solution, or should I rather revert to find_package(CUDA) and cuda_add_executable?

推荐答案

基于@talonmies的评论,我通过为每种语言显式设置变量(即 CUDA CXX :

Based on the comment from @talonmies I found a solution for that problem by setting the variables explicitly for each language, i.e. CUDA and CXX:

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

现在,纯 C ++ 文件是根据C ++ 17编译的,而 CUDA 文件是根据C ++ 14编译的.

Now the pure C++-files are compiled according to C++17, and the CUDA-files are compiled according to C++14.

这篇关于在CMakeLists中组合C ++和CUDA时,将CXX-standard设置为c ++ 17的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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