Is an IDE Necessary for Debugging Fortran Code?

In summary, I am having trouble building a FORTRAN project. I have tried different options but am not sure what they mean. I think I should look into getting a different project type to work.
  • #1
Saladsamurai
3,020
7
Alrighty then :smile: So in order to solve a problem in a previous thread, I simply reinstalled Eclipse, but this time i went with the Parallel Tools Platform since it is supposed to work with FOTRAN too.

I created a C++ project first and did the 'Hello World' thing to make sure it was working. C++ is working fine as far as I can tell.

So I switched to a FORTRAN project and I am having trouble Building. I have a screenshot below. Perhaps someone can help me out with what this might mean? I am used to using Digital Fortran (yeah, I know--old as dinosaurs) where I simply write code, build and run.

Screenshot2011-12-29at123700AM.png
 
Technology news on Phys.org
  • #2
EDIT: I think I should include some more details:

I am using a Mac OS = Snow Leopard.

The exact steps I used to generate the error in the screenshot above:

1) Right-click in Package Explorer: New -> FORRAN Project ->Makefile Project ->Demo Hello World FORTRAN

2) Attempt to Build the source code that was generated by the Hello World Project creation.

*Note:

a) I don't know why I use the 'Makefile' projects, I just saw it in a tutorial. Can someone enlighten me?

b) When I select the Makefile project, there are options in the 'Toolchains' window. I think this might be related to my problem: When the box that says "Show project types and toolchains only if they are supported on the platform" is checked I only see the XLF Tool Chain. But if I uncheck it, I can see GCC Fortran. (See new screen shots below). Selecting the GCC Fortran does not help resolve the issue, but it raises my question of why does is it NOT available when the box IS checked?

With Box checked:

Screenshot2011-12-29at13243AM.png


With Box Unchecked:

Screenshot2011-12-29at13252AM.png
 
  • #3
In your first screenshot you can see a file named "Makefile".
Can you show its contents?
 
  • #4
I like Serena said:
In your first screenshot you can see a file named "Makefile".
Can you show its contents?

Hi ILS :smile: There actually are no contents in the makefile. Perhaps that is the problem. I don't know a lot (anything really) about makefiles. It seems like most "modern" languages don't need you to explicitly make a makefile. Am I correct in saying that? After some Googling, it seems like the types of things that a makefile does are the types of things that get done automatically when you build/link etc.

I have written plenty of FORTRAN code in my graduate work, but never once encountered a makefile. I think I should look into getting a different project type to work. For example, I think that I should be using the option "Executable (GNU Fortran on MacOS X)" would be a more "normal" option. Normal as in 'just type some source code and then run it'.

However I recall that project type gave me errors too. I'll post back momentarily with the new errors. Thanks!
 
  • #5
Hi! ;)

FYI, you always need a file specifying which files to compile and link.
Also where to find include files and libraries.
And in particular which compiler and linker to use.
This information is kept in either a project file or a makefile.

When you already have a makefile you can tell Eclipse to get this information from it by creating a Makefile project.

Otherwise you have to tell Eclipse this, although it can make an educated guess, after which Eclipse generates a makefile and uses that.
 
  • #6
So if I follow these steps:

1) New -> Fortran Project -> Executable (Gnu Fortran on MacOS X)

2) In the Project: New -> source folder

3) In Source folder: New -> Named HelloWorld1.for -> Select from dropdown: fixed form template

Upon running a simple Hello World I get the following screen. Here is what is bothering me:

a) The source folder icon named HelloWorld1 in the package explorer on the left has a little superscripted "C" on it whereas the project folder icon has a superscripted "F". So I think Eclpipse is thinking this is C or something.

b) In the error window there is the C/C++ thing under 'type' which makes me think the same.

Screenshot2011-12-29at23949PM.png
 
  • #7
I think your problem is: "gfortran: command not found."

This error shows that Eclipse does understand that you are compiling a fortran file.

So the question is: do you have gfortran on your system?
And if so, perhaps you need to configure in which directory it is.

In the Console tab-sheet you should be able to see which command is actually given.
Perhaps you can show what it says?
 
  • #8
I do have gfortran installed. I confirmed this by typing: gfortran --version in a terminal window. The console tab contents are as follows.

Code:
**** Build of configuration Debug for project HellowWorld1 ****

make all 
Building file: ../HelloWorld1/HelloWorld1.for
Invoking: GNU Fortran Compiler
gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -o "HelloWorld1/HelloWorld1.o" "../HelloWorld1/HelloWorld1.for"
/bin/sh: gfortran: command not found
make: *** [HelloWorld1/HelloWorld1.o] Error 127

**** Build Finished ****

Thanks again :smile:
 
  • #9
So what happens if you type:

gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -o "HelloWorld1/HelloWorld1.o" "../HelloWorld1/HelloWorld1.for"

in a terminal window?
 
  • #10
I like Serena said:
So what happens if you type:

gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -o "HelloWorld1/HelloWorld1.o" "../HelloWorld1/HelloWorld1.for"

in a terminal window?

I get the following error:

Code:
Last login: Thu Dec 29 14:51:40 on ttys000
Salad-Samurais-MacBook-Pro:~ saladsamurai$ gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -o "HelloWorld1/HelloWorld1.o" "../HelloWorld1/HelloWorld1.for"
gfortran: error: ../HelloWorld1/HelloWorld1.for: No such file or directory
gfortran: fatal error: no input files
compilation terminated.
 
  • #11
Can you change the current directory first to the "HelloWorld1" directory?
That way the gfortran compiler should be able to find the source file "../HelloWorld1/HelloWorld1.for".Anyway, apparently you have a PATH environment problem, meaning that Eclipse cannot find gfortran in the default PATH, but from the terminal window you can.
Did you already reboot your computer?
 
  • #12
I like Serena said:
Can you change the current directory first to the "HelloWorld1" directory?
That way the gfortran compiler should be able to find the source file "../HelloWorld1/HelloWorld1.for".


Anyway, apparently you have a PATH environment problem, meaning that Eclipse cannot find gfortran in the default PATH, but from the terminal window you can.
Did you already reboot your computer?

Hi ILS. I changed to the correct directory (duh :blushing:) and I still get the same error.

With regard to rebooting: Since when do you mean? If you mean since last night, yes. Also, I keep hearing about this PATH thingy, what is that? Is that an environmental variable?

I think we are certainly honing in on the problem: The C++ code works fine, so I wonder why the gfortran is not. I guess we need a way of checking "where" the gfortran compiler and where Eclipse is expecting it to be. As of now, it seems that the problem is that the two are not equal.
 
  • #13
If you are in the correct directory, you should not get the same error...
So apparently you are not in the correct directory.I meant rebooting since you installed fortran...

Let's check this.
Can you type the following commands in a terminal window?

which gfortran
echo $PATH
 
  • #14
I like Serena said:
If you are in the correct directory, you should not get the same error...
So apparently you are not in the correct directory.


I meant rebooting since you installed fortran...

Let's check this.
Can you type the following commands in a terminal window?

which gfortran
echo $PATH

Oof! You're write. I only went to the parent 'project' folder. This is what I get:

Code:
--MacBook-Pro:HellowWorld1 saladsamurai$ cd HelloWorld1
saladsamurai-MacBook-Pro:HelloWorld1 saladsamurai$ gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -o "HelloWorld1/HelloWorld1.o" "../HelloWorld1/HelloWorld1.for"
/var/folders/9K/9KvTsFwDELOjojSdLl+IFU+++TI/-Tmp-//ccQVvBsP.s:unknown:FATAL:can't create output file: HelloWorld1/HelloWorld1.o
saladsamurais-MacBook-Pro:HelloWorld1 saladsamurai$

When I type "which gfortran" I get:

Code:
/usr/local/bin/gfortran

ANd when I type "echo $PATH" I get:

Code:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin
 
  • #15
Can you close eclipse and then restart eclipse from the terminal window by typing:
eclipse

That way Eclipse will inherit the PATH environment variable from your terminal window effectively fixing the problem that gfortran cannot be found.
 
  • #16
Hmmm. When I type eclipse in a terminal I get the error:

Code:
-bash: eclipse: command not found
 
  • #17
Let me guess: eclipse is not on the PATH ? :tongue:
 
  • #18
Okay.
Try to find out where eclipse is and start it with the entire path.
On my linux system it is:
$ /opt/eclipse/eclipse

Perhaps you can find it with:
$ locate eclipse


Saladsamurai said:
Let me guess: eclipse is not on the PATH ? :tongue:

Right! :wink:
 
  • #19
I like Serena said:
Okay.
Try to find out where eclipse is and start it with the entire path.
On my linux system it is:
$ /opt/eclipse/eclipse

Perhaps you can find it with:
$ locate eclipse




Right! :wink:

the locate command needs to generate a database as this is the 1st time I have used it. Before doing so, what exactly am I looking for? Eclipse is weird to me in that it's not installed in my applications folder like all other programs. It's just a 'folder' that I downloaded from the site. I run it by clicking on an icon inside of this folder.

The thing is, I have Eclipse PTP and Eclipse SDK. Both of them have their own folder on my desktop. I run each from within their respective folders. Is that helpul?
 
  • #20
Perhaps you can right-click on the icon and select "Properties" or something like that (I'm not a Mac user).
That should tell you what it's named and where it is...

Alternatively you can try:
$ cd ~/Desktop
$ ls
and see if you can find those folders...

Or perhaps you can drag and drop (or copy and paste) the icon in the Terminal window...

Of perhaps you can open some sort of file explorer and search for a file named eclipse...

Or...
 
Last edited:
  • #21
I like Serena said:
Perhaps you can right-click on the icon and select "Properties" or something like that (I'm not a Mac user).
That should tell you what it's named and where it is...

OK. Also. I just ran that sudo command to generate the database. DO you know how I will know when it is done? I am not used to terminal and it just occurred to me that there is no nice 'time remaining' window to tell me when it is done.

Anywho: Eclipse in: /Users/saladsamurai/Desktop/eclipse PTP

So I typed: /Users/saladsamurai/Desktop/eclipse PTP/eclipse at the terminal and I get the error:

Code:
No such file or directory

I also tried /Users/saladsamurai/Desktop/eclipse PTP/eclipse.app

to no avail.

EDIT: Hold on a minute. Drag and drop is supported in my Terminal. Trying that.
 
  • #22
Try:
$ '/Users/saladsamurai/Desktop/eclipse PTP/eclipse'

(Those spaces in directory names or file names will kill you every time. :wink:)

OK. Also. I just ran that sudo command to generate the database. DO you know how I will know when it is done? I am not used to terminal and it just occurred to me that there is no nice 'time remaining' window to tell me when it is done.

It typically takes a couple of minutes (can also be 15 or more minutes depending how much to do there is on your system), unless it tries to index a DVD or a network drive (which it shouldn't).
You don't have those I hope?
You can see that it's done when the command prompt returns.
 
  • #23
If I drag and drop the launch icon into terminal, I get:

Code:
salad$ /Users/salad/Desktop/eclipse\ PTP/Eclipse.app 
-bash: /Users/salad/Desktop/eclipse PTP/Eclipse.app: is a directory

Maybe Eclipse can't be open from terminal. Can you open it this way in Linux?

Is there another way to accomplish the goal of adding the gfortran directory to the PATH? That is what we are trying to do right?
 
  • #24
Eclipse can be opened from the terminal.
Presumably Eclipse.app is a shortcut file.
Can you inspect its properties?

And yes, we are trying to add gfortran to the path.
Apparently /usr/local/bin is not in your default PATH yet when you boot your computer.
But it is in your path when you start a terminal window.

You could use:
$ ln -s /usr/local/bin/gfortran /usr/bin/gfortran

This will create a symbolic link to gfortran in the directory that will certainly be in your PATH.
It will fix your problem.
 
  • #25
I like Serena said:
Eclipse can be opened from the terminal.
Presumably Eclipse.app is a shortcut file.
Can you inspect its properties?

And yes, we are trying to add gfortran to the path.
Apparently /usr/local/bin is not in your default PATH yet when you boot your computer.
But it is in your path when you start a terminal window.

You could use:
$ ln -s /usr/local/bin/gfortran /usr/bin/gfortran

This will create a symbolic link to gfortran in the directory that will certainly be in your PATH.
It will fix your problem.

I am getting an error in executing this command:

Code:
/Users/saladsamurai
saladsamurais-MacBook-Pro:~ saladsamurai$ ln -s /usr/local/bin/gfortran /usr/bin/gfortran
ln: /usr/bin/gfortran: Permission denied
 
  • #26
Try it with:
$ sudo ln -s /usr/local/bin/gfortran /usr/bin/gfortran
 
  • #27
Okay! That got the symbolic link made. I went back into Eclipse and the Source code Builds successfully without errors/warnings. BUT, when I click: Run ->Run As Local Fortran App I get the error:

Launch Failed: Binary Not Found.

I feel like we are almost there! But without a non-generic error message, I am not sure what the next step is.

Thanks for all of your time and patience so far ILS!
 
  • #28
Check in the Console tab-sheet which executable binary was generated.

Check if you can run it from a terminal window.
You run it with something like:
$ ./HelloWorld1
 
  • #29
I like Serena said:
Check in the Console tab-sheet which executable binary was generated.

It's weird. This is all I get in the Console Tab. A bunch of other stuff appears while it's building. But Upon completion, this is all tere is:

Code:
**** Build of configuration Debug for project HelloWorldProjectInC++ ****

make all 
make: Nothing to be done for `all'.

**** Build Finished ****



Check if you can run it from a terminal window.
You run it with something like:
$ ./HelloWorld1

I am having trouble with this. I am not sure what directory I need to be into run it in this manner. It might be that what I am trying to run has not actually been built.

I swept through all of the directories that I thought I should try running $ ./HelloWorld2 from. All of them gave me the error: -bash: ./HelloWorld2: No such file or directory
EXCEPT when I ran that command from within the /Debug directory. It simpky returned the command prompt to me. I did not actually see any evidence that HelloWorld2 actually ran.


EDIT: This is what I did:

Code:
$ pwd
/Users/SS/Documents/workspace PTP/HelloWorld2/Debug

$ ./HelloWorld2
$
 
  • #30
It appears you tried to build HelloWorldProjectInC++, but that is not in fortran.

Furthermore Eclipse knows there is nothing to do.
Right-click on your project and select "Clean".
Then right-click on your project again and select "Build".
This will force Eclipse to rebuild.

Yes, the Debug directory would be where the executable is.
Apparently it does run there.
It seems it does not print anything, otherwise you would have seen this in the output...
 
  • #31
I like Serena said:
It appears you tried to build HelloWorldProjectInC++, but that is not in fortran.

Furthermore Eclipse knows there is nothing to do.
Right-click on your project and select "Clean".
Then right-click on your project again and select "Build".
This will force Eclipse to rebuild.

Yes, the Debug directory would be where the executable is.
Apparently it does run there.
It seems it does not print anything, otherwise you would have seen this in the output...

OMG. I am really starting to dislike Eclipse. Why would it build 'HelloWorldProjectInC++' when my active window is the source code in my Fortran project? Anywho: After Clean/Build, this is what I get:

Code:
**** Build of configuration Debug for project HelloWorld2 ****

make all 
Building file: ../HelloWorld2SourceFolder/HelloWorld2.for
Invoking: GNU Fortran Compiler
gfortran -funderscoring -O0 -g -Wall -c -fmessage-length=0 -o "HelloWorld2SourceFolder/HelloWorld2.o" "../HelloWorld2SourceFolder/HelloWorld2.for"
Finished building: ../HelloWorld2SourceFolder/HelloWorld2.for
 
Building target: HelloWorld2
Invoking: MacOS X Fortran Linker
gfortran  -o "HelloWorld2"  ./HelloWorld2SourceFolder/HelloWorld2.o   
Finished building target: HelloWorld2
 

**** Build Finished ****

I still get the Binary Not Found error when I try to run it. :cry:
 
  • #32
Check the project explorer window in Eclipse (the left window).
In the Debug directory you should be able to find the binary HelloWorld2.
Right-click it and select Run.

If you can't find it, right-click Debug and select Refresh first.
 
  • #33
I like Serena said:
Check the project explorer window in Eclipse (the left window).
In the Debug directory you should be able to find the binary HelloWorld2.
Right-click it and select Run.

If you can't find it, right-click Debug and select Refresh first.

I don't seem to have any Binaries (And hence the Error). This is all I have (refreshing does not improve):

Screenshot2011-12-29at53706PM.png
 
  • #34
Do you see the document "HelloWorld2" in the Debug folder?
Try right-clicking that...
 
  • #35
I like Serena said:
Do you see the document "HelloWorld2" in the Debug folder?
Try right-clicking that...

Jeesh. I right click that and I can choose 'Run As' -> Run Configurations
Screenshot2011-12-29at55512PM.png


which brings me to the following screen:

Screenshot2011-12-29at55536PM.png


I am not sure where to go from here. Everything is prefilled with the C++ project stuff. I don't understand why. I am clearly right clicking on the HelloWOrld2 bin which is in the fortran project.
 

Similar threads

  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
8
Views
4K
  • Programming and Computer Science
Replies
29
Views
5K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
1
Views
3K
Back
Top