Question

I was trying to compile mpi_prime.c with openmpi on windows. I tried it with the 32bit and 64bit version of OpenMPI_v1.6.2. I got these outputs.

Microsoft (R) C/C++-Optimierungscompiler Version 17.00.61030 für x86
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

mpi_prime.c
Microsoft (R) Incremental Linker Version 11.00.61030.0
Copyright (C) Microsoft Corporation.  All rights reserved.


/out:mpi_prime.exe
/LIBPATH:C:\Entwicklung\OpenMPI_v1.6.2-x64/lib
libmpi_cxx.lib
libmpi.lib
libopen-pal.lib
libopen-rte.lib
advapi32.lib
Ws2_32.lib
shlwapi.lib
mpicxx mpi_prime.c
Microsoft (R) C/C++-Optimierungscompiler Version 17.00.61030 für x86
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

mpi_prime.c
Microsoft (R) Incremental Linker Version 11.00.61030.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:mpi_prime.exe
/LIBPATH:C:\Entwicklung\OpenMPI_v1.6.2-x64/lib
libmpi_cxx.lib
libmpi.lib
libopen-pal.lib
libopen-rte.lib
advapi32.lib
Ws2_32.lib
shlwapi.lib
mpi_prime.obj
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_MPI_Comm_rank" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_MPI_Comm_size" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_MPI_Finalize" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_MPI_Init" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_MPI_Reduce" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_MPI_Wtime" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_ompi_mpi_comm_world" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_ompi_mpi_op_max" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_ompi_mpi_op_sum" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_ompi_mpi_int" in Funktion "_main".
mpi_prime.exe : fatal error LNK1120: 10 nicht aufgelöste Externe

Microsoft (R) C/C++-Optimierungscompiler Version 17.00.61030 für x86
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

mpi_prime.c
Microsoft (R) Incremental Linker Version 11.00.61030.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:mpi_prime.exe
/LIBPATH:C:\Entwicklung\OpenMPI_v1.6.2-win32/lib
libmpi.lib
libopen-pal.lib
libopen-rte.lib
advapi32.lib
Ws2_32.lib
shlwapi.lib
mpi_prime.obj
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_ompi_mpi_comm_world" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_ompi_mpi_op_max" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_ompi_mpi_op_sum" in Funktion "_main".
mpi_prime.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_ompi_mpi_int" in Funktion "_main".
mpi_prime.exe : fatal error LNK1120: 4 nicht aufgelöste Externe

EDIT : Verweis auf nicht aufgelöstes externes Symbol means of course "unresolved reference to external symbol"

So I guess it had something to do with a 32bit vs. 64bit library problem using the wrong .dll as the 32bit version seems to produce less conflicts.

My plan looks like:

  1. get it running on 32bit -> here I'm right now
  2. get it running on 64bit
  3. get it running with another compiler, eg gcc
  4. get it running with my IDE codeblocks
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top