Compile FORTRAN in Eclipse with netcdf

I like interpreted languages such as Matlab or Python, mostly because I’m more like a software user, not developer. These languages usually come with an Integrated Development Environment (IDE) for easy code editing and debugging. However, for compiled languages such as Fortran, there isn’t many choices for IDEs but Eclipse has some potential to be a good alternative.

Steps to compile a Fortran program in Eclipse, in Windows system, using NetCDF library:

  1. Eclipse is a programming platform. To compile Fortran code in Eclipse, a compiler is still needed. I chose cygwin gfortran as it’s easy to configure by the installation wizard.
  2. After installing gfortran in cygwin, install netcdf in cygwin too.
  3. Create a new Fortran project in Eclipse and import the code files.
  4. In properties for the project, select “internal builder” under “Fortran Build”, then in “Tool Chain Editor” choose “cygwin GCC” and “CDT internal builder”. In “Select Tools”, add “GNU Fortran Compiler” and “GNU Fortran Linker”
  5. In “Settings”, define Include locations. Under “GNU Fortran Compiler” -> “Directorories”, add Include paths (-I) as “usr/include” (assuming the NetCDF is installed in this directory”
  6. Same place, define the NetCDF library locations. Under “GNU Fortran Linker” -> “Libraries”, add “netcdff” for “-l” and “usr/lib” for “-L”
  7. Try compile the code. Basically the command is something like
gfortran XX.f90 -L/usr/lib -lnetcdff -I/usr/include

Important Notes:

  • 1) may need to change file suffix from “F90” to “f90” .
  • 2) put the file name “XX.f90” after “gfortran”, followed by “-L, -l, and -I”. I tried to put -L first, won’t work.
  • 3) the paths “/usr/lib” and “/usr/include” are “sudo” Linux paths used in cygwin system. Do not use the absolute windows path (e.g. C:\cygwin64\usr\include) to compile the code. Won’t work.
  • 4) installing NetCDF library yourself (instead of configuring in cygwin) might be a pain. But this video might help.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s