nvcc: treat host compiler warnings as errors, is there a way?

Using nvcc V10.1.105, on Ubuntu 19.04, I tried

/usr/lib/cuda-10.1/bin/nvcc -Xcompiler -Wall -Xcompiler -Werror  main.cu

on source file:

int main() {
  int a;

  return 1;

The compiler prints out

main.cu(2): warning: variable "a" was declared but never referenced

but still produces the a.out file.

Is there a way I can force nvcc to fail when gcc issues any warning?

that doesn’t work! Did I mistype something in my example?

update: that comment above was in response to a deleted comment.

Yes, and the way you do it is exactly what you are showing.

-Xcompiler -Werror

The reason it is not working is because in your test case, the warning is not emitted by gcc. In this case, the warning is being emitted by cicc, which is a NVIDIA sub-tool within nvcc:


(you can discover this with --verbose)

By the time the processed version of this host code actually makes it to the host compiler, the item that triggered the warning seems to be gone, perhaps removed by cicc.

I’m not aware of any documented method to instruct cicc to convert warnings to errors. Simple things like -Xcicc -Werror did not work.

If you’d like to have this capability, you may wish to file a bug at developer.nvidia.com. The instructions are linked to a sticky post at the top of the CUDA programming sub-forum.

Oh, thanks for this excellent explanation, Robert. Wasn’t aware of cicc or other innards of nvcc. Thanks for the link.

The feature I’ll request could also be implemented by simply having nvcc honor a top-level -Werror with no arguments, as gcc does. Then nvcc would presumably figure out how to treat warnings from any sub-tools as errors.