Ubuntu系统中出现系列usr/.../mpi/cxx/file.h:25:undefined reference to MPI::comm:Comm()
问题。选用的是openmpi最新版。
这种情况通常是在编译程序时没有正确链接到 MPI 相关的库文件造成的。
你需要在编译命令中加上 -I /usr/lib/x86_64-linux-gnu/openmpi/include 和 -L /usr/lib/x86_64-linux-gnu/openmpi/lib,以指定 MPI 头文件和库文件的位置。
例如,你可以这样编译:
g++ -o myprogram myprogram.cpp -I /usr/lib/x86_64-linux-gnu/openmpi/include -L /usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi
这样就可以在编译过程中正确链接到 MPI 相关的库文件,避免出现 "undefined reference" 的错误了。