The binary Open MPI distribution for Windows ships with the library built as set of DLLs. The provided .lib
files are simply import libraries for those DLLs. When calling functions from DLLs, their prototypes have to carry the __declspec(dllimport)
extended storage-class attribute in order to allow the compiler to generate a slightly different code to call such functions or to access exported variables. Also functions with the dllimport
storage-class attribute have their names prefixed with _imp_
. Without dllimport
, e.g. for MPI_Init
, the compiler generates reference to the _MPI_Init
symbol while the library actually exports _imp_MPI_Init
, hence resulting in an unresolved symbol error.
Since Open MPI could be compiled either as a set of static libraries or as a set of DLLs, it uses a simple preprocessor mechanism to handle both cases with a single set of header files (e.g. mpi.h
). If the preprocessor symbol OMPI_IMPORTS
is defined, all MPI function prototypes get the dllimport
treatment and do not get it otherwise. The same is true for the function prototypes from the ORTE and OPAL frameworks, with the corresponding preprocessor symbols being ORTE_IMPORTS
and OPAL_IMPORTS
.
To get your code to compile with the binary Open MPI distribution, you should add OMPI_IMPORTS
to the list of preprocessor definitions, which could be found in the project's settings: Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.