My project is mostly C and Fortran, but I had to use MPI from inside a C++ file. I don't want to use C++ wrapper nor link against libmpi_cxx.so
, I use only the plain C interface. But just including mpi.h
in my C++ file is enough for the linker to complain about missing references from libmpi_cxx.so
:
h5pfc -g -lstdc++ *.o -o my_program
../bin/distance_to_wall.o: In function `MPI::Intracomm::Intracomm()':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm.h:25: undefined reference to `MPI::Comm::Comm()'
../bin/distance_to_wall.o: In function `MPI::Intracomm::Intracomm(ompi_communicator_t*)':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/intracomm_inln.h:23: undefined reference to `MPI::Comm::Comm()'
../bin/distance_to_wall.o: In function `MPI::Op::Init(void (*)(void const*, void*, int, MPI::Datatype const&), bool)':
/usr/lib/x86_64-linux-gnu/openmpi/include/openmpi/ompi/mpi/cxx/op_inln.h:121: undefined reference to `ompi_mpi_cxx_op_intercept'
../bin/distance_to_wall.o:(.data.rel.ro._ZTVN3MPI3WinE[_ZTVN3MPI3WinE]+0x48): undefined reference to `MPI::Win::Free()'
../bin/distance_to_wall.o:(.data.rel.ro._ZTVN3MPI8DatatypeE[_ZTVN3MPI8DatatypeE]+0x78): undefined reference to `MPI::Datatype::Free()'
collect2: error: ld returned 1 exit status
Adding -lmpi_cxx
is enough to solve the problem, but this seems a case of paying for what I don't get (I do not use MPI C++ wrapper), nor it seems portable among different MPI implementations, because I have to explicitly list an OpenMPI dependency, which defeats the purpose of using the compiler wrapper in the first case.
Is there a MPI portable way to disable C++ interface upon including mpi.h
on a C++ file?
It is Open MPI specific, but you should be able to disable the C++ interface by defining the macro OMPI_SKIP_MPICXX
.
See: https://github.com/open-mpi/ompi/blob/master/ompi/include/mpi.h.in#L2716