| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html" charset="iso-8859-1"/> |
| <title>Starting a New Project</title> |
| <link rel="stylesheet" type="text/css" href="../help.css"/> |
| </head> |
| <body> |
| <div><p>One of the advantages (or disadvantages) of using Photran is that it does |
| <i>not |
| </i> include a Fortran compiler. Instead, it uses |
| <b>make |
| </b> 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 |
| <b>make |
| </b> program how to compile your Fortran program. |
| </p><ul><li>For small, simple projects, Photran can |
| <b>auto-generate |
| </b> a Makefile which will use the GNU Fortran compiler (gfortran). |
| </li><li>For more complex projects, you can write a custom Makefile. |
| </li></ul><p><b>For more information on project types, |
| </b> click on Help > Help Contents in Eclipse, and navigate to |
| <b>C/C++ Development User Guide > Concepts > CDT Projects. |
| </b></p><h1> Starting a Project with an Auto-Generated Makefile |
| </h1><p>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". |
| </p><ol><li>Click File > New > Fortran Project |
| </li><li>Call it HelloFortran |
| </li><li>Choose "Executable (Gnu Fortran)" from the project type list |
| </li><li>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) |
| </li><li>Click Next |
| </li><li>Click on Advanced Settings |
| </li><li>Expand C/C++ Build in the list on the left, and click on Settings |
| </li><li>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. |
| </li><li>Click on the Error Parsers tab. Check the error parser(s) for the Fortran compiler(s) you will use. |
| </li><li>Click OK |
| </li><li>Click Finish |
| </li><li>Click File > New > Source File |
| </li><li>Call it hello.f90; click Finish |
| </li><li>Type the standard "Hello, World" program shown below, and click File > Save. |
| </li><li>Open the Console view, and make sure "make" ran OK and compiled your program |
| </li><li>In the Fortran Projects view, expand the Binaries entry, and click on your executable (e.g., "HelloFortran.exe - |
| x86le") |
| </li><li>Run | Run As | Run Local Fortran Application |
| </li><li>Choose GDB Debugger (Cygwin GDB Debugger if you're under Windows) |
| </li><li>Check the Console view, and make sure "Hello World" appeared. |
| </li></ol><p><br> |
| <i>hello.f90: |
| </i><pre>program hello |
| print *, "Hello World" |
| end program</pre> |
| </p><h1> Starting a Project with a Hand-Written Makefile |
| </h1><p>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 |
| <a href="http://www.eng.hawaii.edu/Tutor/Make/">http://www.eng.hawaii.edu/Tutor/Make/</a>... and, of course, you can always read the entire manual for GNU Make |
| <a href="http://www.gnu.org/software/make/manual/make.html">http://www.gnu.org/software/make/manual/make.html</a>. |
| </p><ol><li>Click File > New > Fortran Project |
| </li><li>Call it HelloFortran |
| </li><li>Expand "Makefile project" in the project type list (it has a folder icon), and choose "Empty Project" |
| </li><li>Select "-- Other Toolchain --" in the toolchain list in the right-hand column, and click Next |
| </li><li>Click on Advanced Settings |
| </li><li>Expand C/C++ Build in the list on the left, and click on Settings |
| </li><li>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. |
| </li><li>Click on the Error Parsers tab. Check the error parser(s) for the Fortran compiler(s) you will use. |
| </li><li>Click OK |
| </li><li>Click Finish |
| </li><li>Click File > New > Source File |
| </li><li>Call it hello.f90 |
| </li><li>Click Finish |
| </li><li>Type the standard "Hello, World" program shown below. |
| </li><li>Click File > New > File |
| </li><li>Call it Makefile |
| </li><li>Click Finish |
| </li><li>Create a Makefile similar to the one shown below. Again, we assume you are familiar with the structure of a Makefile. |
| <b>You cannot simply copy-and-paste this example |
| </b> 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. |
| </li><li>Click Project > Clean, then click OK |
| </li><li>Open the Console view, and make sure "make" ran OK and compiled your program |
| </li><li>In the Fortran Projects view, expand the Binaries entry, and click on your executable (e.g., "hello.exe - |
| x86le") |
| </li><li>Click Run > Run As > Local Fortran Application |
| </li><li>Choose GDB Debugger (Cygwin GDB Debugger if you're under Windows) |
| </li><li>Check the Console view, and make sure "Hello World" appeared. |
| </li></ol><p><br> |
| <i>hello.f90 |
| </i><pre>program hello |
| print *, "Hello World" |
| end program</pre> |
| <br> |
| <i>Makefile: |
| </i> |
| <b>(You MUST replace the spaces beginning the gfortran and rm lines with a tab character!) |
| </b><pre>all: |
| gfortran -o hello.exe -g hello.f90 |
| |
| clean: |
| rm -f hello.exe |
| </pre> |
| </p><h1> Converting C/C++ Projects to Fortran Projects |
| </h1><p>Every Fortran project is also a C project, so CDT's functionality will work as expected on Fortran projects. However, a C/C++ is |
| <i>not |
| </i>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: |
| </p><ol><li>Switch to the Fortran perspective. |
| </li><li>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. |
| </li><li>The project should now have an "F" icon in the Fortran Projects view. |
| </li></ol><p><center> |
| <img src="../images/Photran-f-vs-c-project.png"></center> |
| </p></div> |
| </body> |
| </html> |