C ++ 11标准与CUDA 6.0 [英] C++11 standard with CUDA 6.0

查看:240
本文介绍了C ++ 11标准与CUDA 6.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的CUDA 6.0项目中为我的C ++文件使用C ++ 11标准。
当我将CUDA 6.0 Nsight Eclipse设置中的编译器更改为g ++并添加 -std = c ++ 11 选项时,我会收到很多错误这个:

I want to use the C++11 standard for my C++ files in my CUDA 6.0 project. When I change the compiler in the CUDA 6.0 Nsight Eclipse settings to the g++ and add the -std=c++11 option then I receive lot of errors like this:

error: namespace "std::__gnu_cxx" has no member "__normal_iterator"

重要的是,我必须为CUDA选择编译器一次,然后为我的C ++文件选择。

Apperantly I have to "select" the compiler once for CUDA and then for my C++ files.

我该怎么办?

推荐答案

问题是CUDA 6.0不支持C ++ 11标准,并且当将 -std = c ++ 11 选项传递给编译器时,其他源代码的编译将失败[特别是当使用第三方.c files JSON,...]。

The problem is CUDA 6.0 does not support the C++11 standard and when passing the -std=c++11 option to the compiler then the compilation of the other source code will fail [especially when using third party .c files JSON, ...].

在CUDA 6.0中实现一个g ++ hack Eclipse:
Project - > Properties - > Build - > Settings - >工具设置 - >构建阶段 - >编译器路径(-ccbin):
这里你输入下面描述的shell脚本的路径[示例]: / home / user / g ++。

"Implement" a g++ hack in CUDA 6.0 Eclipse: Project -> Properties -> Build -> Settings -> Tool Settings -> Build Stages -> Compiler Path (-ccbin): Here you enter the path to the shell script described below [Example]: /home/user/g++.hack

/ home / user / g ++中的脚本hack

# g++ Hack
#

# in CUDA 6.0 the source code is always the last parameter
SourceFile="${@: -1}"

# get the file extension
Extension=${SourceFile##*.}

if [ "$Extension" == "cpp" ]
then
   StdFlag="-std=c++11"
else
   StdFlag=""
fi

# run now the g++ 4.9 in your own path with the personalized std option
/usr/local/bin/g++ $StdFlag $*

别忘了运行 chmod a + x / home / user / g ++。hack 。您的C ++ 11源代码必须具有扩展名.cpp - 对于所有其他扩展,编译器选项不会传递。

Don't forget to run chmod a+x /home/user/g++.hack. Your C++11 Source code must have the extension .cpp - for all other extension the compiler option won't be passed.

我希望它可以帮助,直到Nvidia正式支持C ++ 11。对我来说,它工作,一旦Nvidia将正式支持C ++ 11我可以切换到一个正常解决方案。

I hope it can help until Nvidia officially supports C++11. For me it works and once Nvidia will officially support C++11 I can switch to a "normal" solution.

您将无法在CUDA源代码中使用C ++ 11代码,但至少主机代码可以在C ++ 11中开发!

Note: With this you won't be able to use C++11 code in your CUDA source code but at least the host code can be developed in C++11!

这篇关于C ++ 11标准与CUDA 6.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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