One of the advantages (or disadvantages) of using Photran is that it does not include a Fortran compiler. Instead, it uses make to compile Fortran programs. This allows you to use any Fortran compiler you want, but it also means that a Makefile must be written which tells the make program how to compile your Fortran program.

For more information on project types, click on Help > Help Contents in Eclipse, and navigate to C/C++ Development User Guide > Concepts > CDT Projects.

Starting a Project with an Auto-Generated Makefile

The following is a typical procedure for starting a new project using an auto-generated Makefile. Your system must have the GNU Fortran (gfortran) compiler installed for this procedure to work. To make sure that gfortran is installed, you can open a command prompt (Windows) or terminal window (Linux/Mac) and type "gfortran" (without the quotes); it should respond with "gfortran: no input files".

  1. Click File > New > Fortran Project
  2. Call it HelloFortran
  3. Choose "Executable (Gnu Fortran)" from the project type list
  4. Choose "GCC Toolchain" from the toolchain list (you may need to first uncheck the "Show project types..." check box at the bottom of the window before you can see this)
  5. Click Next
  6. Click on Advanced Settings
  7. Expand C/C++ Build in the list on the left, and click on Settings
  8. Click on the Binary Parsers tab. Check the appropriate parsers for your platform. If you are using Windows, check PE Windows Parser and/or Cygwin PE Parser; if you are using Linux, check Elf Parser; if you are using Mac, check Mach-O parser.
  9. Click on the Error Parsers tab. Check the error parser(s) for the Fortran compiler(s) you will use.
  10. Click OK
  11. Click Finish
  12. Click File > New > Source File
  13. Call it hello.f90; click Finish
  14. Type the standard "Hello, World" program shown below, and click File > Save.
  15. Open the Console view, and make sure "make" ran OK and compiled your program
  16. In the Fortran Projects view, expand the Binaries entry, and click on your executable (e.g., "HelloFortran.exe - x86le")
  17. Run | Run As | Run Local Fortran Application
  18. Choose GDB Debugger (Cygwin GDB Debugger if you're under Windows)
  19. Check the Console view, and make sure "Hello World" appeared.


hello.f90:

program hello
print *, "Hello World"
end program

Starting a Project with a Hand-Written Makefile

The following is a typical procedure for starting a new project using a hand-written Makefile. The following example uses the GNU Fortran (gfortran) compiler, but any Fortran compiler can be used instead. We will assume that you are familiar with how to write a Makefile. If not, there are plenty of resources on the Web, including a tutorial from the University of Hawaii http://www.eng.hawaii.edu/Tutor/Make/... and, of course, you can always read the entire manual for GNU Make http://www.gnu.org/software/make/manual/make.html.

  1. Click File > New > Fortran Project
  2. Call it HelloFortran
  3. Expand "Makefile project" in the project type list (it has a folder icon), and choose "Empty Project"
  4. Select "-- Other Toolchain --" in the toolchain list in the right-hand column, and click Next
  5. Click on Advanced Settings
  6. Expand C/C++ Build in the list on the left, and click on Settings
  7. Click on the Binary Parsers tab.  Check the appropriate parsers for your platform. If you are using Windows, check PE Windows Parser and/or Cygwin PE Parser; if you are using Linux, check Elf Parser; if you are using Mac, check Mach-O parser.
  8. Click on the Error Parsers tab. Check the error parser(s) for the Fortran compiler(s) you will use.
  9. Click OK
  10. Click Finish
  11. Click File > New > Source File
  12. Call it hello.f90
  13. Click Finish
  14. Type the standard "Hello, World" program shown below.
  15. Click File > New > File
  16. Call it Makefile
  17. Click Finish
  18. Create a Makefile similar to the one shown below. Again, we assume you are familiar with the structure of a Makefile. You cannot simply copy-and-paste this example because the gfortran and rm lines must start with a tab, not spaces. The -g switch instructs gfortran to include debugging symbols in the generated executable so that it can be debugged later. The -o switch tells it what to name the generated executable.
  19. Click Project > Clean, then click OK
  20. Open the Console view, and make sure "make" ran OK and compiled your program
  21. In the Fortran Projects view, expand the Binaries entry, and click on your executable (e.g., "hello.exe - x86le")
  22. Click Run > Run As > Local Fortran Application
  23. Choose GDB Debugger (Cygwin GDB Debugger if you're under Windows)
  24. Check the Console view, and make sure "Hello World" appeared.


hello.f90

program hello
print *, "Hello World"
end program

Makefile: (You MUST replace the spaces beginning the gfortran and rm lines with a tab character!)
all:
    gfortran -o hello.exe -g hello.f90

clean:
    rm -f hello.exe

Converting C/C++ Projects to Fortran Projects

Every Fortran project is also a C project, so CDT's functionality will work as expected on Fortran projects.  However, a C/C++ is not a Fortran project until it has been explicitly converted.  (In the Fortran Projects view, a Fortran project will have an "F" icon, while a C/C++ project will have a "C" icon.) To convert an existing C/C++ project to a Fortran project:

  1. Switch to the Fortran perspective.
  2. In the Fortran Projects view, right-click on the project you want to convert, and select Convert to Fortran Project from the pop-up menu.
  3. The project should now have an "F" icon in the Fortran Projects view.