1. Obtain Required Libraries

WRF uses NetCDF to read and write data files, so we’ll need NetCDF for Windows before we can build POP for Windows. You can follow the instructions below to build NetCDF from scratch, or you can go to the downloads section of the NetCDF page and download pre-built binaries.

1.1. Build NetCDF as a Windows DLL

 

  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 paratools-netcdf-4.1.3 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 theLDFLAGS environment 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):

     

 

You are now ready to proceed to Step 2: Port POP from Linux to Windows.


msdevelLogo