views:

402

answers:

2

I am using PGI Visual Fortran in (Windows OS) to build a project/solution consisting of a fortran (f90) library and an executable. The f90 library links to the netcdf.lib. The f90 compiles and builds OK, but when I try to link it to the executable I get the following errors:

Compiling Project ...
Linking...
error LNK2019: unresolved external symbol nf_ _inq_varid_ referenced in function interpnwptools_checkcldliq_
error LNK2001: unresolved external symbol nf__inq varid
error LNK2019: unresolved external symbol nf_ strerror_ referenced in function error
error LNK2019: unresolved external symbol nf_ get_ att_ real_ referenced in function
error LNK2001: unresolved external symbol nf_ get_ att_ real_
error LNK2019: unresolved external symbol nf_ create_ referenced in function ncdf_module_openfile_
error LNK2019: unresolved external symbol nf_def_dim_ referenced in function ncdf_module_openfile_
.
.
.
and a whole other bunch of nf_ unresolved symbols. I don't think that the netcdf library is getting linked properly. Can anyone help? The project that I am using requires netcdf 3.6.0-p1, which I built myself using MS VStudio 2003. I've also tried to build the project using gfortran and eclipse, but have the same linking problem. I've never used netcdf or fortran before... Any suggestions?

A: 

Your suspicion is correct - the NetCDF library is not getting linked properly. Assuming it was properly built, you'll need to tell Visual Fortran where to look to find the library. I don't do any PGI-VF work, but it looks like you can edit the property pages for your project. Look for setting options for the Linker, and you should be able to add directories that the linker will search for the requisite libraries. You may also need to specify the NetCDF libraries themselves as additional dependencies in the Linker Input options.

Tim Whitcomb
Thanks for your answer. I downloaded the netcdf code straight from the netcdf website and built it using MSVS 2003. To build the netcdf library, I used the MSVS windows project provided by netcdf and only had to change the properties to build a .lib instead of a .dll. In PGI-VF, I have specified the netcdf.lib in the linker properties, but it seems that it is not picking it up at all. Could this be the case? I have never worked with F90.... can I link a .lib file with f90? Thanks for the help!
CEOR
+2  A: 

I suspect the problem is that Fortran libraries built with/for different compilers use different calling conventions (name mangling, argument passing, etc.) and are therefore incompatible with each other (in most cases). Try to see if you have the right download and compilation settings for your netcdf library.

FX