Other Compiling and Running Simple Fortran Program in FreeBSD

I'm looking to getting back to doing some elementary programming and scripting. I've dabbled in Python, C, C++, R and even Go but for a variety of insane reasons, I thought I would give Fortran another try (this was the first language I learned in university in the mid-1990's as part of my engineering curriculum). I've found that getting a basic Fortran program up and running in FreeBSD (which I am also very new at) is not an easy task but I've finally managed to compile and run the traditional "Hello World" program. I documented my steps in a wiki I am creating.

I ask so many questions on this forum (and get great answers back) but seldom know enough to help anyone out with their problems so I thought I would share this here in case anyone runs into the same beginner-type issues that I did. Hope it helps.

First, make sure you have installed the lang/gcc compiler. Then create a new file, called helloworld.f:
Code:
program hello
    print *, "Hello World!"
end program hello
To compile the program, run the following command:

gfortran48 --free-form -Wl,-rpath=/usr/local/lib/gcc48 helloworld.f -o helloworld

To execute the program, run:

./helloworld

Note: If you use the .f90 file extension, you can omit the --free-form option.

Sources:
1. https://en.wikibooks.org/wiki/Fortran/Hello_world
2. https://lists.freebsd.org/pipermail/freebsd-current/2012-November/037865.html
3. https://gcc.gnu.org/ml/gcc-help/2005-12/msg00017.html
4. https://en.wikibooks.org/wiki/Fortran/Beginning_Fortran#Free_Form_and_Fixed_Form
5. https://gcc.gnu.org/wiki/GFortranGettingStarted
 
Last edited by a moderator:
Back
Top