Building netCDF on Windows

Compiling netCDF from scratch on Windows is not an easy task since you need a lot of dependencies and, unfortunately, Unidata does not provide and support build project files for Windows. Ideally netCDF would switch to the CMake cross-platform build system because doing so would obsolete maintaining platform and compiler dependent configuration files. Here, we provide a slightly modified source tree of a recent netCDF release and guide you through the build process with CMake and MS Visual C++ on Windows.

Update: Unidata officially provides CMake support since netCDF 4.3.0.

Building Prerequisites

  • Install Microsoft Windows SDK for Windows
  • Install CMake. Make sure CMake is added to PATH.
  • Install Subversion. Make sure svn is in the PATH.
  • Obtain the HDF4 and HDF5 binary releases for your platform (x84/x64) from Install the shared versions, e.g.: (Windows 64-bit CMake VS 2010, Intel Fortran 12), and (Windows 64-bit CMake VS 2008 C, C++, IVF 11.1).
  • Get cURL

In the following examples we assume that dependent libraries will be installed in subdirectories of z:\software\ and its subdirectories bin, include, lib, src. Any other directory is fine though.

Preparing Windows SDK Command Prompt

  • Copy HDF4 and HDF5 DLLs: The HDF Group files are usually located in c:\Program Files\HDF Group. This is OK but to avoid setting up complicated PATHs to all the DLLs we simply copy all DLLs from c:\Program Files\HDF Group\HDF<major-version>\<version>\bin to z:\software\bin.
  • Open Windows SDK Command Prompt and set PATH to our binary dir:
    set PATH=%PATH%;z:\software\bin


  • cURL 7.24.0 is known to work; other versions might fail to compile.
  • extract files in z:\software\src
  • cURL versions greater than 7.21.7 have a bug in the CMakeLists.txt. You need to patch the file curl-<version>/CMakeLists.txt:
    --- curl-7.24.0/CMakeLists.txt.orig     2012-02-27 11:44:29.000000000 +0100
    +++ curl-7.24.0/CMakeLists.txt  2012-02-27 11:44:29.000000000 +0100
    @@ -148,9 +148,9 @@
    -  find_library(WSOCK32_LIBRARY wsock32)
    -  find_library(WS2_32_LIBRARY ws2_32)
    -  list_spaces_append_once(CMAKE_C_STANDARD_LIBRARIES ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY})  # bufferoverflowu.lib
    +  # Windows standard libraries are located in C:/Program Files/Microsoft SDKs/[...]
    +  # They are already included in the default MSVC LIBPATH => no find_library is needed!
    +  list_spaces_append_once(CMAKE_C_STANDARD_LIBRARIES wsock32.lib ws2_32.lib)
         # Remove wldap32.lib from space-separated list
         string(REPLACE " " ";" _LIST ${CMAKE_C_STANDARD_LIBRARIES})
  • In the Windows SDK Command Prompt:
    cd z:\software\src\curl-7.24.0\
    mkdir build
    cd build
  • Invoke CMake:
    cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=z:\software -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_ROOT_PATH="c:\Program Files\HDF Group\HDF5\1.8.8" -DCMAKE_USE_OPENSSL=OFF ..

CMAKE_INSTALL_PREFIX points to the installation directory. The headers, the library and the executables will be installed in the subfolders include, lib and bin respectively. CMAKE_FIND_ROOT_PATH should point to your HDF5 root directory which contains zlib.

Build and install cURL:

nmake install

  • Move libcurl.dll from z:\software\lib to z:\software\bin
  • Type curl --version in the Command Prompt. It should greet you with an info message.


  • Get the sources:
    cd \software\src
    svn checkout svn:// bsd-xdr
  • Edit cmake/ConfigUser.cmake
  • In the Windows SDK Command Prompt:
    cd bsd-xdr
    mkdir build
    cd build
    cmake -G "NMake Makefiles" ..
  • If everything went fine you can now build and install XDR:
    nmake install
  • Check if xdrsizeof_test works in the prompt.

Building netCDF

Once we have installed and build all the library dependencies we can attempt to deploy netCDF.

  • Get the CMake bundled sources of netCDF via subversion from
    cd \software\src\
    svn checkout svn:// netcdf-4.1.3
  • Edit cmake/ConfigUser.cmake and set correct paths to HDF, xdr etc.
  • Build and install:
    cd netcdf-4.1.3
    mkdir build
    cd build
    cmake -G "NMake Makefiles" ..
    nmake install
  • Test if nccopy, ncdump and ncgen work in the prompt


As of netCDF version 4.3.0 these instructions are obsolete. Check out the official build instructions for netCDF using CMake.

Back to GMT build instructions