Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

nullptr is undefined error with nvcc

📅 2014-Feb-18 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Problem

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.

Solution

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