nullptr is undefined error with nvcc


I had a project which had a mix of C++ and CUDA source files. I was using the NVCC compiler to compile both of these types of files. That worked well, until I started using some modern C++ features in the C++ files. To be able to compile them I passed the -std=c++11 flag to the host compiler using the nvcc option -Xcompiler. Then I got compilation errors of this form:

/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error: identifier "nullptr" is undefined

This can also occur if you are using NVIDIA Nsight and specifying this option to the host compiler in it.


NVCC seems to apply the options passed to -Xcompiler to both the C++ (host) and CUDA (device) compiler during the pre-processing stage. The error went away once I specifically used g++ for compiling C++ files and passed the option there. I compiled CUDA files using nvcc, without passing it the option and linked the resulting object files as usual.

Tried with: CUDA 5.5, NVIDIA Nsight 5.5.0, GCC 4.8 and Ubuntu 12.04 LTS

3 thoughts on “nullptr is undefined error with nvcc”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s