Linking NETCDF on Windows OS

Linking NETCDF on Windows OS

I have to use NETCDF under Windows Visual Studio project. I found prebuilt version ftp://ftp.unidata.ucar.edu/pub/netcdf/contrib/win32/netcdf-4.1.1-win32-b... I'm trying to link netcdf as a static library.in VS compiler and linker options I added the following lines :

Fortran - General - Additional Include Dir = "netcdf dll and exe directory"
Linker - General - Additional Library Dir = "netcdf lib directory"
Linker - Input - Additional Dependencies = netcdf.lib

here is my build log :

Compiling with Intel Visual Fortran Compiler XE 12.0.1.127 [IA-32]...
ifort /nologo /debug:full /Od /I"\\netcdf" /warn:interfaces /module:"Debug\\\\" /object:"Debug\\\\" /Fd"Debug\\vc100.pdb" /traceback /check:bounds /libs:static /threads /dbglibs /c /gen-interfaces /Qvc10 /Qlocation,link,"c:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\\\bin" "TestNetcdf.f90"
TestNetcdf.f90(3): error #7002: Error in opening the compiled module file.  Check INCLUDE paths.   [TYPESIZES]
  use typeSizes
------^
TestNetcdf.f90(4): error #7002: Error in opening the compiled module file.  Check INCLUDE paths.   [NETCDF]
  use netcdf
------^
TestNetcdf.f90(7): error #6404: This name does not have a type, and must have an explicit type.   [NF90_INQ_LIBVERS]
  print *, 'NetCDF version: ', nf90_inq_libvers()
-------------------------------^
compilation aborted for TestNetcdf.f90 (code 1)

the fortran code is very simple :

program testnetcdf

  use typeSizes
  use netcdf
  implicit none

  print *, 'NetCDF version: ', nf90_inq_libvers()
  print *, '*** SUCCESS!'  

end program testnetcdf

Tell me, please, what I did wrong ?

12 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The compiler needs to be given the paths to the include and library directories. It was unable to find the module files, since all you told it was

IncludeDir="netcdfdllandexedirectory"

Naturally, it looked for a directory called \netcdf under the working directory, and failed to find it.

The compiler cannot find the module files. Your additional include directories are probably wrong. From your build log the path to the netcdf modules is specified as "\netcdf" - a subdirectory off the root of the current drive. Is this really where you extracted the files?

the problem that this compilation does not contains *.mod files, and it seems there is no other compilation of netcdf for windows (linux version compiles without problems).is it possible to link to netcdf without .mod files ?

If you have netcdf libraries with no Fortran objects or .mod files, your choices appear to be to rebuild the libraries yourself, or to omit the Fortran bindings (call only from C). I thought the instructions for building the entire thing from source were clearer than you've made your method to be.
You would have the option of following the f77 interface guide if you have something against .mod files, but you still need objects built for the calling compiler.
The official pre-built Windows version appears to be specific to MSVC++ 6 32-bit, so it seems unlikely you would attempt to use it on a current system.

The necessary mod files for your test program appear to be in the zip linked to in the initial post.

Before my previous response I had downloaded the zip file you linked and compiled and executed your program using the command line. I had to change the runtime library options from those present in your build-log in order to link successfully, but that was it. Note that I am not a netcdf user and I have not read any documentation, so other problems may befall you, but your sample program appears to work ok.

U:projects>dir netcdf*
 Volume in drive U is ian
 Volume Serial Number is 024E-9CF1

 Directory of U:projects

31/10/2011  12:26 PM              netcdf-test
31/10/2011  12:24 PM              netcdf-4.1.1-win32
               0 File(s)              0 bytes
               2 Dir(s)  69,738,610,688 bytes free

U:projects>cd netcdf-test

U:projectsnetcdf-test>type TestNetCDF.f90
program testnetcdf
  use typeSizes
  use netcdf
  implicit none
  print *, 'NetCDF version: ', nf90_inq_libvers()
  print *, '*** SUCCESS!'
end program testnetcdf

U:projectsnetcdf-test>ifort /I"..netcdf-4.1.1-win32" TestNetCDF.f90 ..netcdf-4.1.1-win32netcdf.lib ..netcdf-4.1.1-win32netcdf_f90.lib
Intel Visual Fortran Compiler XE for applications running on IA-32, Version 1
2.1.1.258 Build 20111011
Copyright (C) 1985-2011 Intel Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:TestNetCDF.exe
-subsystem:console
TestNetCDF.obj
..netcdf-4.1.1-win32netcdf.lib
..netcdf-4.1.1-win32netcdf_f90.lib

U:projectsnetcdf-test>copy TestNetCDF.exe ..netcdf-4.1.1-win32
        1 file(s) copied.

U:projectsnetcdf-test>..netcdf-4.1.1-win32TestNetCDF.exe
 NetCDF version:
 4.0.1-beta3 of Jun  7 2010 14:35:31 $


 *** SUCCESS!

Thank you ! I found mod files. now I can build the project.But netcdf libraries are linked dynamically. I prefer to link them statically.Is there some option to do it in windows ? (in Linux I used -static option for linker)How to configure Visual Studio for static linking ?

Static linking can work only if you have static libraries for NetCDF. If these libraries do, indeed, exist on your system, specify their names (and paths, as needed) in place of the DLL libraries that you used previously.

In general, when you add a third party package dependency to your project, a number of steps are needed to make the integration complete. You have to configure your build system so that these pieces of information are available:

1. The locations of include and module files, needed by the compiler.

2. The locations of libraries, needed by the linker.

3. The locations of DLLs, needed by the newly built application, if any.

4. The locations of configuration files and data files needed by the package, if any.

Providing the information can be by changing settings in VisualStudio, by specifying in build commands, and by environmental variables, or some combination of these three ways.

my netcdf folder has the following files :

hdf5dll.dll
hdf5_hldll.dll
ncdump.exe
ncgen.exe
netcdf.dll
netcdf.h
netcdf.inc
netcdf.lib
netcdf.mod
netcdf_f90.lib
szip.dll
typesizes.mod
zlib1.dll

I indicated this folder for includes, modules, and library filesand in Visual Studio options I clearly indicated two lib files : netcdf.lib and netcdf_f90.libI considered that these .lib files are static libraries for netcdf, is not it?

No, the .lib files are most probably so-called import libraries. On Windows a DLL is typically accompanied
by such an import library, because the linker does not handle the DLLs directly.

You will need a specific set of static netcdf libraries instead.

Regards,

Arjen

>I considered that these .lib files are static libraries for netcdf, is not it?

I do not know the specifics of the NetCDF package, but here are some guidelines. Look at the sizes of the DLL and the corresponding LIB file. If the DLL is much larger than the LIB, the latter is probably just an import library for the DLL. You may also run DUMPBIN /disasm on the .lib file. For an import library, you will see no assembly code at all, but information such as the following:

COFF SYMBOL TABLE
000 009C766F ABS notype Static | @comp.id
001 00000000 SECT2 notype External | MATH_NULL_THUNK_DATA

thank you for explanation! these are import libraries for the DLL; now I understand

Leave a Comment

Please sign in to add a comment. Not a member? Join today