Visual Studio C & Fortran compiling - unresolved extern

I am building a Visual Studio 2010 solution with a Fortran90 project and a C project. I’m using pgf90 and the MSFT C/C++ compiler. The main routine is in C, so per instructions from the web I’ve compiled a static library for all the Fortran routines with the F90 project, and then I made the C project dependent on the static library project.

When the C project builds, I get unresolved references associated with the Fortran routines in the static lib. For example:

2>TestPVFLIBProjec.lib(igtran.obj) : error LNK2019: unresolved external symbol pgf90_alloc03 referenced in function igtran_
2>TestPVFLIBProjec.lib(init_par.obj) : error LNK2001: unresolved external symbol pgf90_alloc03
2>TestPVFLIBProjec.lib(pstep.obj) : error LNK2001: unresolved external symbol pgf90_alloc03

Note that I build things fine on the command line by doing the final link with pgf90. Here I’m using the MSFT C/C++ compiler to link the final solution.

What do I need to include to make this work? Thanks ahead. -Jeff

Hi Jeff,

You need to add the PGI runtime libraries to your link. (Note that I’m assuming that you are linking statically.)

From your VC++ project properties:

Add the PGI library directory, “C:\Program Files\PGI\win64\11.1\lib” to: “Linker | General | Additional Libraries Directories” (Adjust the PATH as necessary)

Then add the PGI Runtime libraries to “Linker | Input | Additional Dependencies”

Here’s the full list:


Finally add “-nodefaultlib:msvcrtd” to “Linker | Command Line | Additional Options”. Note, change “msvcrtd” to “msvcrt” when changing from Debug to a Release build.

Hope this helps,

That did it. Thanks, Mat!