New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Official Windows support via CMake #48

WardF opened this Issue Mar 31, 2016 · 5 comments


None yet
4 participants
Copy link

WardF commented Mar 31, 2016

The cmake files for netcdf-fortran need to be overhauled, to leverage some of the knowledge gained whilst enhancing cmake support in netcdf-c. Part of this effort will also be to include official support for netCDF-Fortran using Windows compilers.

We are a bit hobbled by the fact that there aren't any free compilers (I can find) that are commonly used in conjunction with Microsoft Visual Studio. PGI and Intel Fortran Compilers seem to be the main two our community are using. The Intel compiler pricing is prohibitive at this point, but we should be able to get most of the way there using the PGI compilers.


This comment has been minimized.

Copy link

arjenmarkusdeltaresnl commented Apr 1, 2016

Recently I succeeded in building NetCDF4 on Windows using the MSVC++ and Intel Fortran compilers. The procedure is more or less straightforward, but there is one file that needed patching, The computation of the prefix path is wrong. Here is the code I use for this:

Compute installation prefix relative to this file.

get_filename_component (_dir "@CMAKE_CURRENT_LIST_FILE@" PATH)
get_filename_component (_prefix "@CMAKE_BINARY_DIR@" ABSOLUTE)

Note that I use CMake's "NMake Makefiles" generator and nmake rather than building via Visual Studio. The latter should not be a problem, but I seldom use that method in conjunction with CMake-based projects.


This comment has been minimized.

Copy link

WardF commented Apr 1, 2016

That is encouraging to hear, although I didn't realize you could use "NMake Makefiles" with Visual Studio projects. Thanks for the information re: the prefix path, that will be very helpful!


This comment has been minimized.

Copy link

xiazemin commented Apr 9, 2016

I tried my best to compile it with Visual studio2010 and Intel Fortran 2013 with CMake,but always failed.Can you give me some instructions or share a x86 lib for win7 with me(for research reason)? My email is,Thank you very much.


This comment has been minimized.

Copy link

arjenmarkusdeltaresnl commented Apr 11, 2016

I have used VS 2013 and Intel Fortran 2015 myself. I did create a small batch file to automate things as much as possible, but I also see that it wants either VS 2012 or VS 2013. The reason for that is that the build procedure for HDF5 requires either of these (or else only batch and configuration files for these two environments are provided).

What are the symptoms? What messages do you get?


This comment has been minimized.

Copy link

jbuonagurio commented Feb 6, 2017

I eventually succeeded in building netCDF-Fortran with Intel Fortran 17.0 on Windows. Some notes on the process are below. Any advice is appreciated, maybe I could turn this into a pull request.

netCDF-C Static Library

The Windows distribution for netCDF-C does not include static libraries so you need to build them yourself. I ran CMake with the following arguments, which may vary depending on your HDF5 configuration. If you want to build with a static CRT (/MT) you can also set NC_USE_STATIC_CRT=TRUE, but CMakeLists.txt needs to be rearranged so the macro definition is before the call to specify_static_crt_flag.

-G"NMake Makefiles"

netCDF-Fortran 4.4.4 Static Library

This is easier than a shared build. I ran CMake with the following arguments. This will build the library only; examples and tests will not build because additional libraries need to be passed to the linker and the current CMake script does not support this. These arguments should disable tests, but since there is no ENABLE_EXAMPLES option in CMakeLists.txt you will need to remove ADD_SUBDIRECTORY(examples) manually for a 'clean' build.

-G"NMake Makefiles"
-DCMAKE_Fortran_COMPILER:STRING="C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2017.1.143/windows/bin/ia32/ifort.exe"

I could then build examples with the following 'one-liner', adjust as necessary for your HDF5 configuration:

ifort simple_xy_rd.f -I"E:\netcdf-fortran-4.4.4\fortran" /link
 libzlib.lib libszip.lib libhdf5.lib libhdf5_hl.lib netcdf.lib netcdff.lib msvcrt.lib /NODEFAULTLIB:LIBCMT

netCDF-Fortran 4.4.4 Shared Library

You can use the same CMake arguments for the static library but set BUILD_SHARED_LIBS=TRUE and NETCDF_C_LIBRARY to the shared version of the C library, the one provided in the official Windows distribution will work. This will get you almost all the way there, but I had the exact same issues mentioned by @arjenmarkusdeltaresnl in the Intel Forums:

nf_nc4.f90.obj : error LNK2019: unresolved external symbol _nc_create_par_fortran referenced in function _NF_CREATE_PAR
nf_nc4.f90.obj : error LNK2019: unresolved external symbol _nc_open_par_fortran referenced in function _NF_OPEN_PAR
nf_nc4.f90.obj : error LNK2019: unresolved external symbol _nc_var_par_access referenced in function _NF_VAR_PAR_ACCESS
nf_v2compat.c.obj : error LNK2001: unresolved external symbol _ncerr
nf_v2compat.c.obj : error LNK2001: unresolved external symbol _ncopts

There are two problems here:

  1. The par functions are for parallel netCDF and are not available on Windows. I am guessing this issue would occur on other platforms as well if USE_PARALLEL was not defined in the C library.
  2. For some reason, the linker is not 'seeing' the ncerr and ncopts global variables defined in the declaration modifiers section of netcdf.h. This same problem is also described in a support thread: netCDF #KIS-873279. Not sure why this is happening just yet.

My temporary solution was just to remove all of those function calls from netCDF-Fortran because I didn't need them. I think a proper solution would involve either of a couple options:

  1. On the netCDF-C side: add stubs for par functions even if the parallel build is disabled. Maybe they could just call the non-parallel versions.
  2. On the netCDF-Fortran side: use preprocessor macros to conditionally remove definitions of the par functions, or make them call the non-parallel versions.

I'm not sure yet how to resolve the issue with ncerr and ncopts.

@letmaik letmaik referenced this issue Oct 30, 2017


Incomplete library exports on Windows #554

3 of 9 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment