7

I'm collaborating on an opensource project where the global compiler settings include -Werror and -pedantic, so in order to have my contributions accepted, I'll have to comply with those.

Second, I'm a Windows person, so I have happily built a new component of this project, only to realize now that it doesn't compile on Linux, throwing the following warning:

style of line directive is a GCC extension

on every single line (on every 3rd char to be specific) of a CUDA (.cu) source file that is part of my component.

I'm using cmake with the FindCUDA.cmake scripts to compile CUDA. The source file doesn't contain any #line directive so I'm completely clueless as to what GCC is complaining about.

First I thought it was line-endings, but the Linux "file" command reports the .cu file as "C source, ASCII text", no "with CRLF line terminators".

The rest of the opensource project doesn't contain any CUDA, so I have nothing to compare with.

What does this warning mean exactly, and how do I get rid of it?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
Genoil
  • 777
  • 1
  • 7
  • 18
  • 1
    see http://stackoverflow.com/questions/16519008/why-followed-by-a-number-seems-do-nothing-in-c-plus-plus – m.s. Jun 23 '15 at 11:09

1 Answers1

7

I think what is happening is that nvcc is generating C source from your .cu source files for gcc to consume, and in so doing it is including gcc-style line directives of the form #1234. By compiling this intermediate C code with gcc -pedantic you then get a problem because these are gcc-style line directives and are non-standard. The solution is to not use -pedantic, at least for the CUDA part of the project.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 1
    Thanks. Had to disable all nvcc warnings using --disable-warnings flag because I could not figure out how temporairly disable -pedantic (using #pragma GCC diagnostic didn't do much). Now down to a bunch of [warning: command line option -std=c++11’ is valid for C++/ObjC++ but not for C](http://stackoverflow.com/questions/26867352/cant-get-rid-of-warning-command-line-option-std-c11-using-nvcc-cuda-cma) warnings... – Genoil Jun 23 '15 at 12:30
  • @Genoil, `-Wno-pedantic` (modulo https://stackoverflow.com/questions/50955666/wno-pedantic-ignored-on-older-gcc) – alfC Apr 17 '20 at 20:55