__GNUC__, or not __GNUC__?


with PGI 18.4 I see, that the C and Fortran compiler do not predefine GNUC, but the C++ compiler does predefine it to the value of 7.

Why this inconsistency? In particular, libool (and maybe Autoconf in general) uses some defaults if it detects whether the compiler pretends to be GNU, instead of some heuristic. But this fails for the PGI C++ compiler than.


We consider our C++ compiler to be GNU-compatible, so we set the macro. We do not think our C compiler to be the same, and when we’ve tried to set GNUC from pgcc in the past, it causes more problems than it solves. I’ve been told perhaps the rate of extensions being added to GNU C is slowing down, so that may change in the future.

Unfortunately, pgc++ does not seem to be GNU compatible in regards its compile option. In particular ‘-static’ is not supported. And this option selects libtool based on the predicate, that its a GNU ‘compatible’ compiler. Though, it has heuristics to select ‘-Bstatic’ for PGI compilers, which do not pretend to be GNU compatible.

Just as a datapoint, Intel and LLVM/Clang also pretends to be GNU, but at least also supports the ‘-static’ flag.

Hmm. I’ve been at PGI for a while and never associated “GNU compatible” with compiler option compatible, but I see your point. Are there others? Especially if the GNU switch has a one-to-one correspondence to a PGI one, I will open an RFE to address that.

At least Autotools/Libtool are build on this assumption. In this particular case, Libtool would have selected -Bstatic for PGI compilers. I’m not aware of other flags though.



This is tracked in FS#25999.