title: Compiling a Fortran program with netCDF and Intel Fortran on Windows 10
body: <p>I have some Fortran code which uses netCDF for reading and writing files on Linux. On Linux based systems I build netcdf-c, hdf5 &amp; zlib.</p>
  
  <p>Attempting to build on Windows, I have ifort ( 19.1.0.166 ) and Visual Studio 2019 installed and <a href="https://www.unidata.ucar.edu/software/netcdf/docs/winbin.html" rel="nofollow noreferrer">netCDF-C 4.7.3 ( netCDF-4 64 bit )</a></p>
  
  <p>I have adapted the call from the Makefile used on Linux as below.</p>
  
  <pre><code>&gt;ifort -I"C:\Program Files\netCDF 4.7.3\include" /O2 /real-size:64 /Qdiag-disable:5117 /Qopenmp src\unptrackmod.f90 src\readSSMmod.f90 src\calcConnectivity.f90 src\unptrack.F90 src\readwritenc.f90 "C:\Program Files\netCDF 4.7.3\lib\hdf5.lib" "C:\Program Files\netCDF 4.7.3\lib\netcdf.lib"
  </code></pre>
  
  <p>Which results in:</p>
  
  <pre><code>src\readwritenc.f90(7): error #7002: Error in opening the compiled module file.  Check INCLUDE paths.   [NETCDF]
        use netcdf
  ----------^
  src\readwritenc.f90(35): error #6404: This name does not have a type, and must have an explicit type.   [NF90_OPEN]
          status = nf90_open(path = filename, mode = nf90_nowrite, ncid = ncid)
  -----------------^
  src\readwritenc.f90(36): error #6404: This name does not have a type, and must have an explicit type.   [NF90_NOERR]
          if (status .ne. nf90_noerr) call handle_nf_err(status)
  ------------------------^
  src\readwritenc.f90(39): error #6404: This name does not have a type, and must have an explicit type.   [NF90_INQ_VARID]
            status = nf90_inq_varid(ncid, "nbe", varid)
  -------------------^
  src\readwritenc.f90(41): error #6404: This name does not have a type, and must have an explicit type.   [NF90_GET_VAR]
          status = nf90_get_var(ncid, varid, nbe)
  </code></pre>
  
  <p>The source for the program that I am attempting to compile is <a href="https://github.com/gillibrandpa/unptrack" rel="nofollow noreferrer">available here</a></p>
  
  <p>Is it necessary to build netCDF from source on Windows to be able to read and write netCDF files from Fortran?</p>
  
  <h2>Further detail</h2>
  
  <p>After compiling netCDF-c with CMake and running Visual Studio as Administrator 
  , netCDF was installed to <code>C:\Program Files (x86)\netCDF\</code> with a netcdf.dll written to the include directory and a netcdf.lib in the lib directory.</p>
  
  <p>Assigning these paths to the netcdf-fortran entries (NETCDF_C_INCLUDE_DIR, NETCDF_C_LIBRARY, NETCDF_INCLUDE_DIR) in the CMake-gui, reconfigure and generating the Visual Studio solution again.</p>
  
  <pre><code>1&gt;------ Build started: Project: netcdff, Configuration: Release x64 ------
  1&gt;nf_v2compat.obj : error LNK2019: unresolved external symbol ncerr referenced in function c_ncabor
  1&gt;nf_v2compat.obj : error LNK2019: unresolved external symbol ncopts referenced in function c_ncgopt
  1&gt;C:\netcdf-fortran\fortran\Release\netcdff.dll : fatal error LNK1120: 2 unresolved externals
  </code></pre>
  
  <p>I deleted <code>nf_v2compat.c</code> to get rid of the errors above and the INSTALL build succeeds with NC4F, writing <code>bin\netcdff.dll</code> &amp; <code>include\netcdf.inc</code> files. I added the <code>NC4F\bin</code> &amp; lib paths to 'Additional Library Directories' in Linker > Input &amp; netcdff.dll to 'Additional Dependencies' and include path to Additional Include Directories, but the original compilation errors still occur.</p>
  
  <p>Running dumpbin /exports netcdff.dll returns:</p>
  
  <pre><code>Dump of file netcdff.dll
  
  File Type: DLL
  
    Summary
  
          1000 .data
          1000 .pdata
          1000 .rdata
          1000 .reloc
          1000 .rsrc
          1000 .text
  </code></pre>
  
  <p>Which I understand to mean it is being built incorrectly.</p>
  
  <p>Although not an answer to my original question, I eventually used Cygwin with gfortran to build the dependencies.</p>