NetCDF is a popular data format in the scientific computing community. ParaTools offers pre-compiled binary packages for Windows and instructions for compiling NetCDF 4.1.3 with the PToolsWin development environment.


Cross-compile with PToolsWin

The following instructions assume that you are working from the command line in HPC Linux.

  1. ParaTools developed the PToolsWin development environment specifically for porting Linux applications to Windows. PToolsWin is distributed as part of HPC Linux. Download and install HPC Linux, either in a virtual machine or natively.

  2. Open a command line in your HPC Linux distro and load the PToolsWin module:



  3. Create your NetCDF folder:


  4. Download and extract the NetCDF 4.1.3 source code from Unidata to $NETCDFDIR:


  5. There’s a bug in NetCDF that prevents it from cross compiling. Fortunately, we’ve developed a patch. Download and apply  netcdf patch to the NetCDF source:



  6. Move the NetCDF source code to a sub-folder:


  7. NetCDF includes a configuration script that will automatically generate the makefiles we need. Configure NetCDF as follows. Be sure to type the whole command as one line:


    Let’s take a closer look at this command. We are executing the configure script according to the standard GNU build process. The –prefix flag tells the configure script where to install files after they are compiled. –host=x86_64-w64-mingw32 is very important because it tells the configure script to use the MinGW compiler instead of the default GNU compiler. Without this flag, NetCDF would build for Linux, not Windows. –enable-dll and –enable-shared tell configure that we want shared libraries and that those libraries should be Windows DLL files. We use the –disable-netcdf-4 flag to disable obsolete functionality. By setting the LDFLAGSenvironment variable we are passing flags directly to the program linker. -Wl,–export-all-symbols,–enable-auto-import tells the linker to automatically make all NetCDF functions and subroutines accessible to programs that link against the NetCDF DLLs. Without these flags, the DLL files will be created but your programs will not be able to link with them. Adding “-DgFortran” to CPPFLAGS is required when building with gfortran on Linux.

  8. Once the configure script is finished, build and install NetCDF. (!) If you have multiple cores in your machine, you can reduce compilation time by passing the ‘-j<ncpus>’ flag to make (e.g. ‘make -j4’).


  9. Some versions of GNU Libtool insert invalid -l flags on the linker command line. If your build fails with something like this:

    then you will need to fix the postdeps line in libtool.

    1. Open ${NETCDFDIR}/netcdf-4.1.3/src/libtool in a text editor.

    2. Scroll to the very bottom of the file and locate the line that begins with “postdeps=”
    3. Remove any invalid -l flags from that line. For example, if you see -l -L/usr/local/..., change it to -L/usr/local/...

    4. Once you’re satisfied, save the file and run ‘make’ and ‘make install’ again.
  10. If everything went well you should see the following message:
    If you do not see this message, review your commands for errors and try again.
  11. The final step is to link the DLL files from the bin directory to the lib directory:

    This is necessary because Linux makefiles and build scripts expect program libraries to be in the lib directory, but Windows expects them to be in the same path as the program executables. Making the files accessible at both locations keeps both ends of the cross-compilation process happy.

  12. Here is what the NetCDF bin and lib folders look like after a successful compilation ($NETCDFDIR is /home/livetau/windows):

The NetCDF Windows DLL functions in exactly the same way as a Linux shared object library. Call NetCDF functions from your C, C++, or Fortran code just as before, and link against the DLL when you compile. Make sure that$NETCDFDIR/netcdf-4.1.3/include is in your compiler’s include search path (e.g. use the -I flag) and that$NETCDFDIR/netcdf-4.1.3/lib is in the linker path (e.g. use the -L flag). For example, you could modify your Makefile or set these environment variables before you compile: