Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Getting Started with Standard Make"

m (Instering the first hello world file)
m
 
(One intermediate revision by one other user not shown)
Line 15: Line 15:
 
Insert '''hello.f90''' to be the name of the file. "Browse" <small>("Alt+O")</small> to the folder "hello".  "Alt+f“, „return" to finish, then paste this program:
 
Insert '''hello.f90''' to be the name of the file. "Browse" <small>("Alt+O")</small> to the folder "hello".  "Alt+f“, „return" to finish, then paste this program:
  
<code>
+
    program hello
program hello
+
    print *, "hello world"
print *, "hello world"
+
    end
end
+
</code>
+
  
 
==Creating the make file==
 
==Creating the make file==
Line 25: Line 23:
 
Once again open the "New:Select a wizard". Select "General > Untitled Text File" and paste the following in the new tab
 
Once again open the "New:Select a wizard". Select "General > Untitled Text File" and paste the following in the new tab
  
<code>
+
    all :
all :
+
        gfortran hello.f90
gfortran hello.f90
+
</code>
+
  
 
(''Beware!'' Not Whitespaces but "tab" in second line)
 
(''Beware!'' Not Whitespaces but "tab" in second line)
 
  
 
Now save the modified text file <small>("Ctrl + s")</small>. Enter '''makefile''' as a filename. Insert '''hello''' in the parent folder cell <small>("Alt + e")</small> and save it.
 
Now save the modified text file <small>("Ctrl + s")</small>. Enter '''makefile''' as a filename. Insert '''hello''' in the parent folder cell <small>("Alt + e")</small> and save it.
Line 43: Line 38:
 
Create the new „Fortran > Source file“ > '''module1.f90''' <small>(Source Folder should already be selected correctly)</small>, hit "enter". Paste
 
Create the new „Fortran > Source file“ > '''module1.f90''' <small>(Source Folder should already be selected correctly)</small>, hit "enter". Paste
  
<code>
+
    module module1
module module1
+
    contains
contains
+
    subroutine hi()
subroutine hi()
+
    print *, "hi from module1"
print *, "hi from module1"
+
    end subroutine
end subroutine
+
    end
end
+
 
</code> and save it.
+
and save it.
  
 
Change to the "hello.f90" tab <small>("Ctrl + Page Up")</small>. Select all <small>("Ctrl + a")</small> and replace by
 
Change to the "hello.f90" tab <small>("Ctrl + Page Up")</small>. Select all <small>("Ctrl + a")</small> and replace by
<code>
+
 
program hello
+
    program hello
use module1
+
    use module1
print *, "hello world"
+
    print *, "hello world"
call hi
+
    call hi
end
+
    end
</code> and don't forget to save it.
+
 
 +
and don't forget to save it.
  
 
Change the tab to "makefile". Change it in the following way:
 
Change the tab to "makefile". Change it in the following way:
  
<code>
+
    all :
all :
+
        gfortran module1.f90 hello.f90
gfortran module1.f90 hello.f90
+
</code>
+
  
 
Build and test the program in one operation, by simply pressing "Ctrl + F11"
 
Build and test the program in one operation, by simply pressing "Ctrl + F11"
Line 73: Line 67:
  
 
Create new sourcefile "bye.f90", and fill it with
 
Create new sourcefile "bye.f90", and fill it with
<code>
+
 
program bye
+
    program bye
use module1
+
    use module1
call hi
+
    call hi
print *, "and bye"
+
    print *, "and bye"
end program
+
    end program
</code>.
+
 
  
 
Change the makefile to
 
Change the makefile to
<code>
+
 
all : hello bye
+
    all : hello bye
module1.mod : module1.f90
+
    module1.mod : module1.f90
gfortran -c module1.f90
+
    gfortran -c module1.f90
module1.o : module1.f90
+
    module1.o : module1.f90
gfortran -c module1.f90
+
    gfortran -c module1.f90
hello : module1.o hello.o
+
    hello : module1.o hello.o
gfortran -o hello module1.o hello.o
+
    gfortran -o hello module1.o hello.o
hello.o : module1.mod hello.f90
+
    hello.o : module1.mod hello.f90
gfortran -c hello.f90
+
    gfortran -c hello.f90
bye : module1.o bye.o
+
    bye : module1.o bye.o
gfortran -o bye module1.o bye.o
+
    gfortran -o bye module1.o bye.o
bye.o : module1.mod bye.f90
+
    bye.o : module1.mod bye.f90
 
gfortran -c bye.f90
 
gfortran -c bye.f90
</code>
 
  
 
Build the project. Then select "hello - [x86/Ie]" in the "Fortran Project" bar. Press on the run-button <small>(white triangle in a green circle)</small> to test it.
 
Build the project. Then select "hello - [x86/Ie]" in the "Fortran Project" bar. Press on the run-button <small>(white triangle in a green circle)</small> to test it.
Line 102: Line 95:
  
 
You should see something like  
 
You should see something like  
<code>
+
 
hi from module1
+
    hi from module1
and bye
+
    and bye
</code>
+
 
 
To find out how you can manage modules without editing the makefile proceed to the [[Getting Started with Managed Make]] tutorial.
 
To find out how you can manage modules without editing the makefile proceed to the [[Getting Started with Managed Make]] tutorial.
 +
 +
[[Category:Photran]]

Latest revision as of 22:22, 6 July 2009

This tutorial demands almost no knowledge of elcipse, make and fortran. Here emphasis is layed on learning how to perform basic tasks while quickly navigating through the different wizards and windows, which otherwise could consume a lot of time and attention. In more advanced tutorials hints to basic shortcuts will be omitted.

Setting up the project "hello"

Start the "New: Select a wizard" from „File > New > Other“(Hint: Hitting "Ctrl+n" gets you there faster).

Select „Fortran Project“ (Hint: Insert >"Fotran" in the 'Wizards' field, then Fortran can be selected by clicking 2 times "tab" and "arrow down" ). Now go to the next Page (Hint: Press "Alt+n").

Type >"hello" in the „Project name“. It will be used as the folder. Select the project type: "Make project > Empty Project" and „GCC Tool Chain“. (Here again: 2 times "tab" to go to „Project type“, then the "arrow keys" and „+“ to open "Make project > Empty Project" . Press „tab“ to select „GCC Tool Chain“). Press "return" to finish (if it asks whether to open the associated perspective, select „Remember my decision“ and „Yes“).

Instering the first "hello world" program hello.f90

As before start the "New:Select a wizard". Then select „Fortran > Source File“ (Hint: Insert >"source"; 2 x "tab" + arrows to "Fortran > Source File"). Hit „return“ to go to "Next".

Insert hello.f90 to be the name of the file. "Browse" ("Alt+O") to the folder "hello". "Alt+f“, „return" to finish, then paste this program:

   program hello
   print *, "hello world"
   end

Creating the make file

Once again open the "New:Select a wizard". Select "General > Untitled Text File" and paste the following in the new tab

   all :
       gfortran hello.f90

(Beware! Not Whitespaces but "tab" in second line)

Now save the modified text file ("Ctrl + s"). Enter makefile as a filename. Insert hello in the parent folder cell ("Alt + e") and save it.

Building and testing the program

Press "Alt + p", „b“ to build the project. "Ctrl + F11" and "Enter" to run resulting binary (the selection C/C++ | Fortran, and the debugger is only important for debugging purposes, so you can just hit enter twice).

Introducing modules

Create the new „Fortran > Source file“ > module1.f90 (Source Folder should already be selected correctly), hit "enter". Paste

   module module1
   contains
   subroutine hi()
   print *, "hi from module1"
   end subroutine
   end

and save it.

Change to the "hello.f90" tab ("Ctrl + Page Up"). Select all ("Ctrl + a") and replace by

   program hello
   use module1
   print *, "hello world"
   call hi
   end

and don't forget to save it.

Change the tab to "makefile". Change it in the following way:

   all :
       gfortran module1.f90 hello.f90

Build and test the program in one operation, by simply pressing "Ctrl + F11"

Managing multiple executables and modules

Create new sourcefile "bye.f90", and fill it with

   program bye
   use module1
   call hi
   print *, "and bye"
   end program


Change the makefile to

   all : hello bye
   module1.mod : module1.f90
   	gfortran -c module1.f90
   module1.o : module1.f90
   	gfortran -c module1.f90
   hello : module1.o hello.o
   	gfortran -o hello module1.o hello.o
   hello.o : module1.mod hello.f90
   	gfortran -c hello.f90
   bye : module1.o bye.o
   	gfortran -o bye module1.o bye.o
   bye.o : module1.mod bye.f90

gfortran -c bye.f90

Build the project. Then select "hello - [x86/Ie]" in the "Fortran Project" bar. Press on the run-button (white triangle in a green circle) to test it. Select "bye - [x86/Ie]" and run it.

You should see something like

   hi from module1
   and bye

To find out how you can manage modules without editing the makefile proceed to the Getting Started with Managed Make tutorial.

Back to the top