Xcode/gfortran Contest Winner: Damien Bobillot

NOTE: This plugin will not work with Xcode 2.5 or 3.0. And will not work in Leopard at all. The plugin will work on Mac OS X Tiger with Xcode 2.4.

UPDATE UPDATE UPATE UPDATE UPDATE UPDATE UPDATE

A newer version of the plugin, installer and gfortran is now available. Please see the following news item:

http://www.macresearch.org/xcode_gfortran_plugin_update

About a month or so ago, we put out a call for someone to develop a gfortran plugin for Xcode. Damien Bobillot has stepped up to the plate and produced a plugin that meets the requirements of the contest. As a result of his winning entry, Damien will receive a 4GB iPod Nano. You can download all of the files necessary to begin using the plugin directly from the MacResearch site (see below). Detailed instructions for using the plugin, as well as possible remedies for troubleshooting are given below.

One of the requirements for the contest was that the plugin source be made publicly available. It is our hope that others will take advantage of Damien's good work to help extend and improve the plugin and make the changes available to the community at large. If you do modify the plugin, please keep in mind that crediting author is Damien Bobillot, and please let us know that an update is available. If there is enough development interest, MacResearch can host a repository on the project.

Thanks again Damien for your work on this and enjoy the prize!

MacResearch Mirror
gfortran compiler for ppc archive
gfortran compiler for intel archive
gfortran plugin and templates installer
gfortran plugin source

NOTE: The current plugin does not produce Universal Binaries
NOTE: The binaries for gfortran provided here are from hpc.sourceforge.net and may install in a directory different from the most current version on that site (currently the version here is the August 2006 build). They are provided here as a convenience to get the plugin to work in a standard configuration. The credit for creating these binaries belongs to Gaurav Khanna. Thanks to Gaurav for allowing us to mirror the current distribution here.

gfortran compiler instructions

You must use either the August 2006 version of gfortran from Gaurav's site OR the version supplied here. It must be installed using the method described below. If you have a newer version of gfortran installed, please see the note at the end of the document on how to modify the source to create an updated plugin. The plugin has been tested in Xcode 2.4.

1) Download the gFortran compiler appropriate for your system.
2) Unpack the archive using the following command.

(PPC): sudo tar -zxvf gfortran-ppc-bin.tar.gz -C /
(Intel): sudo tar -zxvf gfortran-intel-bin.tar.gz -C /

Note: If your browser tried to unpack the archive and you have a tar archive instead of a .tar.gz file issue the one of the following commands instead:

(PPC): sudo tar -xvf gfortran-ppc-bin.tar -C /
(Intel): sudo tar -xvf gfortran-intel-bin.tar -C /

Install the gfortran plugin and templates

1) Download the package installer for the gfortran plugins and templates
2) Unzip that archive and run the installer.

The installer will install a fortran file template in:

/Library/Application Support/Apple/Developer Tools/File Templates

and it will install the plugin into:

/Library/Application Support/Xcode/Plug-ins

Using the plugin

1) Start up Xcode 2.4

2) Create a new project File > New Project > Command Line Utility > Standard Tool

3) Name the project "fortran"

4) Right click on the Source folder and select Add > New File...

5) Scroll down to the Gfortran option and select "Gfortran" as the file type

6) If you like rename the file (for this example it will stay untitled.f)

7) Edit the file as in the following image

8) Click on the top level project icon and then click on the "Get Info" button

9) For Architectures make sure only ppc is present (if on Intel set it to i386)

10) Expand the Targets group in the main project window, select the target (called "fortran" if you named the project as in step 2) and click "Get Info". IMPORTANT: Make sure ONLY pcc OR i386 is present (as in step 9).

11) Edit main.c as in the image below (note the trailing underscore after the call to the test function)

12) Set the build type to Release. Click on Build and Go. You should see something similar to the image below

Troubleshooting:

1) This plugin does not yet produce Universal Binaries. The source code is provided for anyone who wishes to extend the application.

2) If you get a link time error (especially in Debug mode on PPC based systems) you may need to add the gfortran libraries to the project directly. Do the following:

a) With your project still open, open a new terminal window and type:

cd /usr/local/lib
open ./

b) Drag libgfortran.a to the project pane (place it anywhere, but under the "Source" group is convenient.

c) Try building the application again.

If the above fails, try switching your build settings to Release instead of Debug.

Important note: Regarding Debug vs. Release. Depending on the system type PPC or Intel you are using, the Debug mode may require that you always include the gfortran library as part of the build process (this is because ZeroLink currently doesn't work, at least for the PPC version of the plugin). However, you may find that when you switch to Release builds, the program gives a warning about a missing dylib at runtime. In that case, remove the explicit gfortran library from the project and rebuild the application. It should then run as normal. Alternatively, just compile in release mode all of the time.

Alternate gfortran:

There are a number of places that the fortran compiler settings are set. You can view these in the source code in the following files:

fortran.pbcompspec (ExecPath variable)
BDCompilerSpecificationGFortran.m (~lines 55-60)

Changing those settings should allow you to use another build of gfortran (or gfortran installed in an alternate location).

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Thanks, Damien!

Thanks, Damien.

Damien has reverse engineered the Xcode plug-in architecture and has made language plug-ins for other languages, including Ada, which work very well. A bit of poking around in his plug-in quickly reveals that he has done an enormous amount of work to accomplish this, in lieu of Apple making the necessary information publicly available.

Jerry

Excellent plugin!

However, I was not able to compile the code. I followed the tutorial but in the moment of compiling I get the following error:

[Session started at 2006-12-13 11:18:19 -0500.]
Hello, World!
ZeroLink: unknown symbol '_test_'

fortran has exited due to signal 6 (SIGABRT).

======
Obviously, it is the typical underscore problem. Unfortunately, I am not able to find in Xcode the variable that I need to change to solve such a problem :-( Any idea???

Re: Excellent plugin!

I missed a part in the tutorial that I forgot to update. You need to turn ZeroLink off:

1) In the Groups and Files Pane open the Targets disclosure triangle and click once on the app (in the example above it's called fortran)
2) Click on the Info button in the toolbar
3) Click the Build tab
4) Find the ZeroLink setting and uncheck the checkbox

Try to build again.

Dave

Thank you, now it is

Thank you, now it is working!

Uninstalling the gfortran plugin

I keep getting errors under xcode for the gfortran plugin. How can I remove it in an orderly manner, so that I could perform a clean re-install?

Re: Uninstalling the gfortran plugin

Hello,

The files for the plugin templates are placed in:

/Library/Application Support/Apple/Developer Tools/File Templates

and the plugin itself is in:

/Library/Application Support/Xcode/Plug-ins

Note that we have a new installer using a newer version of gfortran available at:

http://www.macresearch.org/xcode_gfortran_plugin_update

Once you remove the old version, you may just want to try the new installer. If you are on an Intel Mac choose Custom Install.

Regards,

Dave

Getting the Xcode debugger to work with gfortran

I have a lot of legacy FORTRAN code and was pretty excited to hear about a gfortran plugin for Xcode (thanks!). However, I couldn't get the debugger to work with it. I thought this latest update would possibly fix it but after downloading and installing it I still couldn't get it to work, e.g., ignoring breakpoints, not displaying variables. I had even followed the suggestions above.

Finally, it occurred to me that no symbols were being generated. This was after comparing the Build settings for a C program with those for FORTRAN.

Here's what I did:

1. In the project window, Groups & Files pane, select your target (open the Targets group) and then click the Info button in the toolbar.
2. In the Target "myfprog" Info window select the Build tab.
3. Select Configuration: Debug (pop-up).
4. Select Collection: Language (pop-up under GCC Fortran source compiler).
5. There's only one setting: OTHER_FORTRANFLAGS.
6. To the right in the Value column, double click and enter "-g" (w/o the quotes) and "return".
7. Close the Info window, rebuild (w/ Debug as the Active Build Configuration) and then run the debugger. You should now see the program pause at your breakpoints and the current module's variables displayed.

Make sure you select the Target Info and make these settings. It doesn't seem to work if Project Info is selected and the -g option is added there.

Also, it's not necessary (updated plugin?) to use a C program as a front end to call your FORTRAN code. Things seem to run fine from a main FORTRAN program.

Hope this helps. I couldn't seem to find any information to get the debugger to work with the gfortran plugin.

Re: Getting the Xcode debugger to work with gfortran

Yes. You are correct you don't need to have any C files for the plugin to work. That was just part of the example to show that you can mix and match C and Fortran at will. The plugin will work with straight fortran.

Thanks for pointing that out,

Dave

c-front-end

Could you quickly explain how to get rid of the C-front-end?
Thanks,
Claus

Re: c-front-end

Hi Claus,

Check out:

http://www.macresearch.org/xcode_tutorial_fortran_only_projects

Regards,

Dave

Auto variable list?

Many thanks, jstingley. I am now able to stop at break points. But there is no variable automatically listed. As a new mac/gfortran user, I know how to view "simple" variables individually through Expressions. But is there anyway to configure Xcode to automatically list local variables? How do I view a particular element (row/column) of an array?

I think many of us new users have been waiting for a particular article on debugging fortran programs. I was able to find one online

http://lists.apple.com/archives/Fortran-dev/2006/Mar/msg00011.html

But as a novice to mac, I am unable to understand the instructions without step-by-step instruction with illustrations. :(

Could you please help me out? Many thanks.

problems debugging fortran

Hi,
I have fortran compiling just fine for a while. I never really needed debugging, but now I was curious -- and it doesn't work. I tried these things (all of which were mentioned at some point) on a gfortran project that compiles well:
- set the architecture to ppc for the project and the target (running on powerbook G4, 10.4.8)
- adding the libfortran.a file
- setting the -g flag
- uncheck zerolink
- trying debug vs. release configuration

When I hit "build and debug",
this happens:

[Session started at 2007-03-24 14:38:51 +0100.]
GNU gdb 6.3.50-20050815 (Apple version gdb-573) (Fri Oct 20 15:54:33 GMT 2006)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-apple-darwin".
Loading program into debugger…

tty /dev/ttyp2
Program loaded.
sharedlibrary apply-load-rules all
run
[Switching to process 5490 local thread 0xf03]
Running…
Enter the filename of the file with the data to be sorted!

Which is ok, then I enter the file name, and then nothing happens. At the bottom left corner of the xcode window it continuously says GDB:running.
When I place a breakpoint before the first WRITE statement, it ignores it.

Does anybody have an idea why that is and get the debugger to work?

Thanks,
Claus

Using Xcode with gfortran and a Makefile

Since a lot of those who are going to be working with Fortran will be working with legacy code, and might want/need a Makefile, I thought I would list the steps to take to get Xcode to work with legacy fortran code (including a Makefile).

1. File -> New Project. In the window that pops up choose "Standard Tool" in the "Command Line Utility" submenu.

2. Delete All the files in source (When prompted: Tell it to delete the files and refrences).

3. Drag all fortran code files into the source folder (When prompted: Click on Default). -Note: this will keep the folder structure and paths.

4. Delete the target (When prompted: Click on Default).

5. Project -> New Target. (When prompted choose: External Target).

6. Give the target a name when prompted.

7. In the Target settings set Arguments to: "PATH=/usr/local/bin:/other/paths/bin:$PATH $(ACTION)"

8. In the Target settings set Directory to the path of the folder where you want the executable and .o files to be placed. I want the executable (and the .o) to be placed in the same folder as the Makefile (as a simple Makefile would), in the case of the program that I am currently writing this is: "/Users/3/Lewis_Group/Programming/xyzSTATS"

9. Right-Click on the Executable Icon.

10. When prompted. Add: New Custom Executable

11. When prompted give the executable a name.

12. Set Executable Path to the path of of the executable (this includes the .x executable that you would have made if you typed make). In the case of the project that I am currently working on this is "/Users/3/Lewis_Group/Programming/xyzSTATS/xyzSTATS.x"

13. Finishing Step 12 will bring up a new window. In "Set the working directory to:" choose "Custom directory." Then set the path to be the directory in which your Makefile puts the executable.

Following these steps will allow you to use "Build" and "Build and Go". I have not tried to use Debug yet, so I don't know if there is anything special that needs to happen when using a Makefile. Hopefully, someone will post a reply describing what steps to take, if we do need to do something special.

do'h

Man, sometimes you wonder...
I haven't touched fortran on the mac for a while, cause I hadn't gotten debugging to work (see comment above).
Today I gave it another try. With your book, Drew. In xcode there is an option:
Debug -- Standard I/O log

Man, I was always sort of wondering where I could enter stuff during debugging... Now I know... :-)

What a bummer that was...

Cheers!

Installation problem?

I'm running OS X 10.4.11 and Xcode 2.5

I follow the install directions step-by-step, but when I get to step 4, Add File.. there is no Gfortran listed as a file type. What am I doing wrong?

Thanks for the help ahead of time..
-Sean

installation problems.... step 4 from installation

I'm running OS X 10.5 (leopard) and Xcode 2.5

I follow the install directions step-by-step, but when I get to step 4, Add File.. there is no Gfortran listed as a file type. What am I doing wrong?

Thanks for the help ahead of time..

Christopher

(This exactly the same problem as sean has...)

Using the plugin: no gfortran option

I am having the same problem with choosing gfortran.

Using the plugin: no gfortran option

I have the same issue. I am using Leopard 10.5.1 & Xcode 3 on a dual 2.5MHz Mac G5 PPC w/ 8MG RAM. As far as I can tell, the installer failed to place the plug-in into the folder as indicated in the instructions. I cannot find a trace of the plug-in anywhere on my system, at least with Spotlight. I thought that there may be a problem with the installation of Xcode & the Developer tools, so I re-installed them from the Leopard install dvd. No improvement. I guess I cannot blame Xcode 3 for the problem, since seanstavro & cbonnett had their problem using Xcode 2.5.
Thanks.
-David

Re: Xcode plugin for gfortran on Leopard/Xcode 2.5 and 3.0

Hi Everyone,

The plugin for gfortran an Xcode doesn't work in Xcode 3 (and probably not in Xcode 2.5 for the same reasons). Specifically, the plugin architecture for Xcode has changed significantly between the previous release (2.4) and now. The only way to run a fortran compiler with the Xcode tools is to use the Organizer (which there is tutorial about here on MacResearch), or to get the Intel compilers.

We're looking into a way to get the gfortran plugin to work again, but it's not looking too promising at the moment.

Sorry for the inconvenience. I've modified the story to make this clear above.

Regards,

Dave

xcode 3.0

I'm actually using xcode 3.0

sorry for the confusion

Similar error

[Session started at 2008-02-13 20:15:31 -0500.]
Hello, World!
ZeroLink: unknown symbol '__gfortran_st_write'

fortran has exited due to signal 6 (SIGABRT).

This seems to be another error related to ZeroLink. I've gotten the plugin to work fine for the case where you don't use the C front end, which is how I'll be using it for the most part. But I'd like to figure this one out. I'm new to fortran, so I'm hoping there's a simple answer I don't see.

Gfortran with xCode 2.4.1

I have xCode 2.4.1 installed and can't seem to get the plugin working (no Gfortran option in Source->Add->New File... Do I need to go down to 2.4 (which I don't have a copy of)?

Bryan

gfortran and gdb

Dear Damien

I am running xcode 3.1 on a macbook with Mac OS X 10.5.6 (Kernel Version: Darwin 9.6.0) and need to run and debug fortran code compiled with gfortran with the gdb debugger which is installed with xcode. Gfortran compiler 4.3 (installed with the gfortranCompleteInstaller) works well, but gdb does not recognise debugger code produced with the -g option.
The following message comes for every object file to link:

warning: Could not find object file "/var/folders/Q9/Q9nXi-k1GTSFi+Wv73Er3k+++TI/-Tmp-//cc6O6B22.o" - no debug information available for "order.for".

Does this have to do with the fact, that i cannot use the fortran plugin because of the 3.1 xcode version, although i am using gdb outside xcode, or am i confusing something?

Note: My gdb debugger works well with gfortran on linux.

I would appreciate for any suggestions.

Nik

How to install?

I don't know if I should even pose my question in this forum because all the discussions here are hi-tech. Anyways, I just graduated from college with chemical engineering degree and am going to grad school in fall 2009. I am new with Mac and programming. However, I need to learn programming because I am sure I can't go around it for my future research projects.

Ok, I downloaded the gfortran installer and it seemed I installed it too. I also downloaded the plugins and binaries ( I hope). Also have a simple code written in textedit (input.rtf). I don't know what to do next. Please help!!!!!

I know most of you will take this forgiven but trust me I have spent two full days trying to find out how to do these things. Any help would be appreciated very much.

Sincerely
Santosh Koirala

Plug in Fixed! (sorta)

Go here for a fix to the plugin to allow it to function with xcode 3.1.3: http://www.macresearch.org/fortran-plugin-xcode-31#comment-15419

I don't use Xcode with

I don't use Xcode with FORTRAN, nor do I plan to. My plan is to use cgdb and gfortran. That works for me. If you have macports working, then you can get cgdb that way. cgdb is very well done.

There are several significant challenges getting gfortran and gdb to work together. They are surmountable. I am not going to worry about Xcode.

One problem I've found is that distributed binaries needed by gfortran (e.g. the libraries for linking) contain debug information. That really messes things up. So, I now use the strip command (strip -S filename) to remove the debug info from library files that link to gfortran. A useful resource is the otool -L command that tells you which libraries are linked in to an executable. Those libraries need to be stripped (often reducing their size significantly). First copy to a backup just in case (I've trashed the OS by accidental trashing of a gcc library file!).

You might need to try different gfortran options to work well with the debugger. -g might work, but sometimes -gdwarf-2 is needed (also try -ggdb and -g2). I can't recall any consistency to this. I've found one of these options works. I just use one that works. See the web site: gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#Debugging-Options .

Finally, the debugger v7 does not work well at all. I work with the 6.5.X version that Apple supplies. You'll find the later one out there, but I have not had success with it.

-Tony