blob: 1f247826ab2c9255627f812b1bbe76e02a9763d5 [file] [log] [blame]
<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 &gt; Help Contents in Eclipse, and navigate to
<b>C/C++ Development User Guide &gt; Concepts &gt; 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 &quot;gfortran&quot; (without the quotes); it should respond with &quot;gfortran: no input files&quot;.
</p><ol><li>Click File &gt; New &gt; Fortran Project
</li><li>Call it HelloFortran
</li><li>Choose &quot;Executable (Gnu Fortran)&quot; from the project type list
</li><li>Choose &quot;GCC Toolchain&quot; from the toolchain list (you may need to first uncheck the &quot;Show project types...&quot; 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 &gt; New &gt; Source File
</li><li>Call it hello.f90; click Finish
</li><li>Type the standard &quot;Hello, World&quot; program shown below, and click File &gt; Save.
</li><li>Open the Console view, and make sure &quot;make&quot; ran OK and compiled your program
</li><li>In the Fortran Projects view, expand the Binaries entry, and click on your executable (e.g., &quot;HelloFortran.exe -
x86le&quot;)
</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 &quot;Hello World&quot; appeared.
</li></ol><p><br>
<i>hello.f90:
</i><pre>program hello
print *, &quot;Hello World&quot;
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 &gt; New &gt; Fortran Project
</li><li>Call it HelloFortran
</li><li>Expand &quot;Makefile project&quot; in the project type list (it has a folder icon), and choose &quot;Empty Project&quot;
</li><li>Select &quot;-- Other Toolchain --&quot; 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.&nbsp; 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 &gt; New &gt; Source File
</li><li>Call it hello.f90
</li><li>Click Finish
</li><li>Type the standard &quot;Hello, World&quot; program shown below.
</li><li>Click File &gt; New &gt; 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 &gt; Clean, then click OK
</li><li>Open the Console view, and make sure &quot;make&quot; ran OK and compiled your program
</li><li>In the Fortran Projects view, expand the Binaries entry, and click on your executable (e.g., &quot;hello.exe -
x86le&quot;)
</li><li>Click Run &gt; Run As &gt; 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 &quot;Hello World&quot; appeared.
</li></ol><p><br>
<i>hello.f90
</i><pre>program hello
print *, &quot;Hello World&quot;
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:
&nbsp;&nbsp;&nbsp;&nbsp;gfortran -o hello.exe -g hello.f90
clean:
&nbsp;&nbsp;&nbsp;&nbsp;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.&nbsp; However, a C/C++ is
<i>not
</i>a Fortran project until it has been explicitly converted.&nbsp; (In the Fortran Projects view, a Fortran project will have an &quot;F&quot; icon, while a C/C++ project will have a &quot;C&quot; 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 &quot;F&quot; icon in the Fortran Projects view.
</li></ol><p><center>
<img src="../images/Photran-f-vs-c-project.png"></center>
</p></div>
</body>
</html>