5

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"

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

How can I do it? Installing CUDA 6.5 - which supports undocumented C++11 - is not an option.

Peter VARGA
  • 4,780
  • 3
  • 39
  • 75
  • 2
    This question appears to be off-topic because it is not a question – talonmies Sep 20 '14 at 04:18
  • I am new in StackOverflow and first it was a question which I could answer myself - according to http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ – Peter VARGA Sep 20 '14 at 05:47
  • 2
    There is nothing wrong with answering your own question on Stack overflow. The problem is there no question and no answer here. – talonmies Sep 20 '14 at 14:32
  • 1
    I don't make the rules. This isn't me, it the whole of [SO]. If you want share information, do so. But do it as a question and pair. Like this: http://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api . Otherwise expect to have this deleted. It is a simple as that – talonmies Sep 20 '14 at 15:38
  • @talonmies: Yes, I changed it already. As I wrote I am new and it is not my intention not to meet the forum rules... – Peter VARGA Sep 20 '14 at 15:48

1 Answers1

7

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, ...].

"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

The script in /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 $*

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.

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.

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!

Peter VARGA
  • 4,780
  • 3
  • 39
  • 75