[mpich-discuss] LNK2019 error on Windows 7 and Visual Studio 2008 using MPI

Darcy Allison plasma.simulation at gmail.com
Wed Jul 25 13:43:36 CDT 2012


I am trying to compile a simple c++ MPI program using Visual Studio 2008 
(professional) and MPICH2 on Windows 7 professional.

I downloaded and ran the x86_64 (version 1.4.1p1) msi file from the 
MPICH2 website.

I have set C:\Program Files\MPICH2\bin as a Path variable.

I have tried two different ways to set the include and lib directories 
in my Visual Studio MPI project. The first is to set both of them under 
Tools->Options->Projects and Solutions->VC++ Directories.

My program is very simple as I am just trying to get MPI to work on 
Windows for the first time.
------------------------------------------------------------------------
#include <mpi.h>
#include <cstdio>

int main(int argc, char *argv[])
{
     int pid;
     int numpid;

     MPI_Init(&argc,&argv);

     MPI_Comm_size(MPI_COMM_WORLD,&numpid);
     //get the rank of the current process and store it in the pid variable
     MPI_Comm_rank(MPI_COMM_WORLD,&pid);
     printf("Hello from processor %d of %d!\n",pid,numpid);

     MPI_Finalize();

     return 0;
}
------------------------------------------------------------------------

I get the following errors when I try to compile it:
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol _MPI_Finalize 
referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Comm_rank 
referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Comm_size 
referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Init 
referenced in function _main
1>Y:\ModelCenter_LinkingCodes\zonair_mpi\Debug\zonair_mpi.exe : fatal 
error LNK1120: 4 unresolved externals

I believe this tells me that it is not linking in the MPI library files.

The other way is to go to Project->Properties->Configuration 
Properties->C/C++->General->Additional Include Directories. I then put 
"C:\Program Files\MPICH2\include" in the box.

Then I go to Project->Properties->Configuration 
Properties->Linker->General->Additional Library Directories. I then put 
"C:\Program Files\MPICH2\lib" into the box.

Finally, I go to Project->Properties->Configuration 
Properties->Linker->Input->Additional Dependencies. I then put mpi.lib 
into the box.

Now when I compile I get the exact same error message:
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol _MPI_Finalize 
referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Comm_rank 
referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Comm_size 
referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Init 
referenced in function _main
1>Y:\ModelCenter_LinkingCodes\zonair_mpi\Debug\zonair_mpi.exe : fatal 
error LNK1120: 4 unresolved externals

What am I missing to get it to compile?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20120725/b2a3ff4f/attachment.html>


More information about the mpich-discuss mailing list