nvcc C++ compilation fails

Hello all,

I have been using CUDA on windows for a while and decided i needed to start porting the code to linux.

In windows I used the --host-compilation=c++ flag to force the compiler to compile my code (which contains C++ strings, exceptions, …) and it worked without problems. If I try to compile my code on linux however, nvcc doesn’t seem to accept --host-compilation, it just keeps compiling it as C code, thus giving me some(allot) errors when using the STL.

This is the code i use to compile:

nvcc --host-compilation=c++   -o Output.o -c Input.cu

(I did trace the problem to the STL usage)

Any ideas about what i might be doing wrong? I searched for a while but could find anything.

Thx in advance,

Hellraiser

I’m wondering about this flag. I run CUDA on openSUSE 11 and it works fine with C++ without any compiler flag.

edit: I assume you did not use gcc/g+±compiler on windows, right? Well, perhaps your code is translatet with g++ ( the linux c++ compiler ) but your code is just incompatible.

I remember having some problems like this on ubuntu, too, however I don’t really remember how I worked around them.

Hi,

Thx for the replies!

I dont have much time to look into this error at the moment (lots of other things to do) but I fixed it for now with a regular const char * instead of a std::string

Regards,

Hellraiser

One thing that might be worth trying is to check you have g++ installed

IIRC I had a problem where some C++ was failing to compile (not finding STL) because I had gcc but not g++ (I think its actually the same compiler but different default include paths)

Just a thought…

Hello HellraiserDark,

the manual page for nvcc says:

--host-compilation <language>

Specify C vs. C++ language for host code in CUDA source files.  Allowed values for this option:  ’C’,’C++’,’c’,’c++’.  Default value:  ’C++’.

So my first guess would be to just leave the whole –host-compilation option away because C++ is enabled by default.

Sometimes when I want to write pure C code it happens that I mix in C++. In my case the option

--host-compilation;c

works fine to find all the places where I coded C++ accidently.

My nvcc version is this one:

kwk@~:$ nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2007 NVIDIA Corporation

Built on Thu_Jun_19_04:48:21_PDT_2008

Cuda compilation tools, release 2.0, V0.2.1221

I hope this helps you!