Preprocessing macro __GNUC__ undefined for mpic++

Hello, it seems that the preprocessing macro GNUC is undefined for mpic++ but defined for pgc++.
I’m not sure whether the issue is with pgc++ or the mpi wrapper, but the issue does not occur for Intel so I’m posting here first.

The following example code demonstrates the problem.

#ifdef __GNUC__
#warning "__GNUC__ is defined"
#warning "__GNUC__ is not defined"

With recent versions of OpenMPI and pgc++, the compile-time output is:

mach5% mpic++ --version

pgCC 15.10-0 64-bit target on x86-64 Linux -tp sandybridge
The Portland Group - PGI Compilers and Tools
Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
mach5% mpirun --version
mpirun (Open MPI) 1.10.1

Report bugs to
mach5% mpic++ -c test.cpp
"test.cpp", line 4: warning: #warning directive: "__GNUC__ is not defined"
  #warning "__GNUC__ is not defined"

mach5% pgc++ -c test.cpp
"test.cpp", line 2: warning: #warning directive: "__GNUC__ is defined"
  #warning "__GNUC__ is defined"

I’ve tried PGI 15.10 with OpenMPI 1.10.1 (shown here) and PGI 12.9 with OpenMPI 1.6.2. Intel 16.0 with OpenMPI 1.10.1 does not have this problem.

Well, I found (after some digging) the source of the above problem. mpic++ points to pgCC (or pgcpp), which is not the same as pgc++. A PGI post helped me understand what is going on:

Passing the --gnu flag to mpic++ solves almost all of my problems, except the following issue.

Consider the following code:

#include <mpi.h>
int main()
  int id;
  MPI_Comm_rank(MPI_COMM_WORLD, &id);
  return 0;

The code compiles fine with mpic++, but fails when compiling with mpic++ --gnu.

mach5% mpic++ simple_mpi.cpp
mach5% mpic++ --gnu simple_mpi.cpp
/tmp/pgCCOryb4A-0xatp.o: In function `MPI::Intracomm::Intracomm()':
/stage/mpi/OpenMPI/1.10.1/PGI/15.10/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to `MPI::Comm::Comm()'
/tmp/pgCCOryb4A-0xatp.o: In function `MPI::Intracomm::Intracomm(ompi_communicator_t*)':
/stage/mpi/OpenMPI/1.10.1/PGI/15.10/include/openmpi/ompi/mpi/cxx/intracomm_inln.h:23: undefined reference to `MPI::Comm::Comm()'
/tmp/pgCCOryb4A-0xatp.o:(.data._ZTVN3MPI8DatatypeE[_ZTVN3MPI8DatatypeE]+0x78): undefined reference to `MPI::Datatype::Free()'
/tmp/pgCCOryb4A-0xatp.o:(.data._ZTVN3MPI3WinE[_ZTVN3MPI3WinE]+0x48): undefined reference to `MPI::Win::Free()'

I feel like I’m missing a library or something, but I’ve been unable to find it.
I have tried passing my specific gcc version (4.8.3) and other versions. As before, this is with PGI 15.10 and OpenMPI 1.10.1.

Hi Ross,

Sorry, but you’ll need to rebuild OpenMPI to using pgc++ (aka pgcpp --gnu) or g++. Different C++ compilers use different name mangling so the OpenMPI symbol names in object files will be different depending upon if you built using g++ naming or our older pgcpp name mangling.

  • Mat