I'm compiling a CUDA program - a simple and innocuous one. Regardless of how far I simplify it or remove some of the code or the include files, nvcc tells me:
In file included from /usr/local/cuda/bin/..//include/crt/common_functions.h:271:0,
from /usr/local/cuda/bin/..//include/common_functions.h:50,
from /usr/local/cuda/bin/..//include/cuda_runtime.h:115,
from <command-line>:0:
/usr/local/cuda/bin/..//include/crt/math_functions.h:8891:5: error: "_GLIBCXX_MATH_H" is not defined [-Werror=undef]
I'm using CUDA 9.0 or 9.1 on Linux, and CUDA is using GCC (either 5 or 6). Why is this happening and how can I fix it?
In CUDA 9.0 and 9.1, nVIDIA is a bit sloppy about using certain macros before checking they've been defined. That is, indeed, a sort-of-an issue with the header files crt/math_functions.h
, crt/math_functions.hpp
and math_functions.hpp
(in the CUDA include directory).
However, this is usually not an actual problem, since an undefined macro defaults to a value of 0 (in C and probably in C++ too). And indeed, by default, neither gcc nor nvcc will complain.
In your case, however, something is making GCC run with -Wundef
, which warns you about these cases, and -Werror
, which escalates all warnings into errors. Since what you're invoking is nvcc
, the command-line (which you, likely, did not write yourself) probably has -Xcompiler="-Wundef"
and -Xcompiler="-Werror"
somewhere.
Removing the latter of these two will make nvcc
succeed (barring other errors), and removing both will make the warnings go away as well.