user1412135
user1412135

Reputation: 123

Openmpi compiling error: mpicxx.h "expected identifier before numeric constant"

I'm trying to compile a program with openmpi, my code does not give any errors but instead one of the mpi headers does:

/usr/include/openmpi-x86_64/openmpi/ompi/mpi/cxx/mpicxx.h:168: error: expected identifier before numeric constant
/usr/include/openmpi-x86_64/openmpi/ompi/mpi/cxx/mpicxx.h:168: error: expected unqualified id before numeric constant

The relevant line of code in the header simply reads:

namespace MPI {

I am using the mpiCC compiler. Am I doing something wrong? or is this a bug in openmpi?

Thanks in advance.

Upvotes: 2

Views: 2281

Answers (2)

Jinzhe Zeng
Jinzhe Zeng

Reputation: 73

I got this error when I passed -DMPI to the compiler, which conflicts with namespace MPI.

Using -DMPI=MPI fixed the error.

In CMake:

target_compile_definitions(obj_mpi PRIVATE $<$<COMPILE_LANGUAGE:C,CXX>:MPI=MPI>)

Upvotes: 0

Massimiliano
Massimiliano

Reputation: 8032

Though I am not able to reproduce the problem you encountered, the following comments can be found in mpi.h, from which mpicxx.h is included:

/*                                                                             
 * Conditional MPI 2 C++ bindings support.  Include if:
 *   - The user does not explicitly request us to skip it (when a C++ compiler
 *       is used to compile C code).
 *   - We want C++ bindings support
 *   - We are not building OMPI itself
 *   - We are using a C++ compiler
 */
#if !defined(OMPI_SKIP_MPICXX) && OMPI_WANT_CXX_BINDINGS && !OMPI_BUILDING
#if defined(__cplusplus) || defined(c_plusplus) 
#include "openmpi/ompi/mpi/cxx/mpicxx.h"
#endif
#endif

If you are not using the deprecated C++ bindings, then a possible workaround is to add

-DOMPI_SKIP_MPICXX

to your CXXFLAGS. Hope this may help.

Upvotes: 1

Related Questions