C++ 致命错误:mpi.h:没有这样的文件或目录#include <mpi.h>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26920083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fatal error: mpi.h: No such file or directory #include <mpi.h>
提问by user2804865
when I compile my script with only
当我只用编译我的脚本时
#include <mpi.h>
it tells me that there is no such file or directory. But when i include the path to mpi.h as
它告诉我没有这样的文件或目录。但是当我将mpi.h的路径包含为
#include "/usr/include/mpi/mpi.h"
(the path is correct) it returns:
(路径正确)它返回:
In file included from /usr/include/mpi/mpi.h:2087:0,
from lbm.cc:7:
/usr/include/mpi/openmpi/ompi/mpi/cxx/mpicxx.h:35:17: fatal error: mpi.h: No such file or directory
#include "mpi.h"
^
compilation terminated.
Anyone know how to fix this?
有人知道怎么修这个东西吗?
采纳答案by Wesley Bland
The problem is almost certainly that you're not using the MPI compiler wrappers. Whenever you're compiling an MPI program, you should use the MPI wrappers:
问题几乎可以肯定是您没有使用 MPI 编译器包装器。无论何时编译 MPI 程序,都应该使用 MPI 包装器:
- C -
mpicc
- C++ -
mpiCC
,mpicxx
,mpic++
- FORTRAN -
mpifort
,mpif77
,mpif90
- C -
mpicc
- C++ -
mpiCC
,mpicxx
,mpic++
- FORTRAN -
mpifort
,mpif77
,mpif90
These wrappers do all of the dirty work for you of making sure that all of the appropriate compiler flags, libraries, include directories, library directories, etc. are included when you compile your program.
这些包装器为您完成了所有繁重的工作,以确保在编译程序时包含所有适当的编译器标志、库、包含目录、库目录等。
回答by Gregory Alan Bolcer
On my system, I was just missing the Linux package.
在我的系统上,我只是缺少 Linux 包。
sudo apt install libopenmpi-dev
pip install mpi4py
(example of something that uses it that is a good instant test to see if it succeeded)
(使用它的例子是一个很好的即时测试,看看它是否成功)
Succeded.
成功了。
回答by Gregory Alan Bolcer
On my system Ubuntu 16.04. I installed :
在我的系统 Ubuntu 16.04 上。我安装了:
sudo apt install libopenmpi-dev
after I used mpiCC to compile and it works
在我使用 mpiCC 进行编译后,它可以工作了
回答by jeremy_rutman
As suggested above the inclusion of
如上所述,包括
/usr/lib/openmpi/include
in the include path takes care of this (in my case)
在包含路径中处理这个(在我的情况下)
回答by Marc J. Driftmeyer
Debian appears to include the following:
Debian 似乎包括以下内容:
- mpiCC.openmpi
- mpic++.openmpi
- mpicc.openmpi
- mpicxx.openmpi
- mpif77.openmpi
- mpif90.openmpi
- mpiCC.openmpi
- mpic++.openmpi
- mpicc.openmpi
- mpicxx.openmpi
- mpif77.openmpi
- mpif90.openmpi
I'll test symlinks of each for mpic, etc., and see if that helps the likes of HDF5-openmpi enabled find mpi.h.
我将针对 mpic 等测试每个符号链接,看看这是否有助于启用 HDF5-openmpi 之类的工具找到 mpi.h。
Take that back Debian includes symlinks via their alternatives system and it still cannot find the proper paths between HDF5 openmpi packages and mpi.h referenced in the H5public.h header.
收回 Debian 通过他们的替代系统包含符号链接,它仍然无法找到 HDF5 openmpi 包和 H5public.h 标头中引用的 mpi.h 之间的正确路径。
回答by Bvacavar
You can execute:
你可以执行:
$ mpicc -showme
result :
结果 :
gcc -I/Users/<USER_NAME>/openmpi-2.0.1/include -L/Users/<USER_NAME>/openmpi-2.0.1/lib -lmp
This command shows you the necessary libraries to compile mpicc
此命令显示编译 mpicc 所需的库
Example:
例子:
$ mpicc -g -I/Users/<USER_NAME>/openmpi-2.0.1/include -o [nameExec] [objetcs.o...] [program.c] -lm
$ mpicc -g -I/Users/<USER_NAME>/openmpi-2.0.1/include -o example file_object.o my_program.c otherlib.o -lm
this command generates executable with your program in example, you can execute :
此命令在示例中使用您的程序生成可执行文件,您可以执行:
$ ./example
回答by Hung Tran
On Fedora:
在 Fedora 上:
dnf install openmpi-devel