我正在尝试使用 openmpi 编译程序,我的代码没有给出任何错误,但 mpi 标头之一却出现了错误:
/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
标题中的相关代码行简单地写着:
namespace MPI {
我正在使用 mpiCC 编译器。难道我做错了什么?或者这是 openmpi 中的一个错误?
提前致谢。
虽然我无法重现您遇到的问题,但可以在
mpi.h
中找到以下评论,其中包含mpicxx.h
:
/*
* 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
如果您不使用已弃用的 C++ 绑定,则可能的解决方法是添加
-DOMPI_SKIP_MPICXX
给你的
CXXFLAGS
。希望这会有所帮助。
当我将
-DMPI
传递给编译器时出现此错误,这与 namespace MPI
冲突。
使用
-DMPI=MPI
修复了错误。
在 CMake 中:
target_compile_definitions(obj_mpi PRIVATE $<$<COMPILE_LANGUAGE:C,CXX>:MPI=MPI>)