Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

warriervineetha

macrumors newbie
Original poster
Jul 21, 2016
2
0
Canada
I have an issue on mac os x El Capitan with Xcode 7. I'm using fortran 6.1, downloaded from https://gcc.gnu.org/wiki/GFortranBinaries. I would like to know how I can run fortran77 codes using fortran.
I have tried
gfortran hello.f77 -o a.out
and got the following error:

ld: warning: ignoring file hello.f77, file was built for unsupported file format ( 0x20 0x70 0x72 0x6F 0x67 0x72 0x61 0x6D 0x20 0x6D 0x61 0x69 0x6E 0x0A 0x0A 0x63 ) which is not the architecture being linked (x86_64): hello.f77 Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status

Please refer:
http://stackoverflow.com/questions/37954802/fortran77-fortran95-compilers
 
Last edited:

cqexbesd

macrumors regular
Jun 4, 2009
175
42
Germany
I'm no fortran expert (I say that a lot these days...). Is old_fortran.f77 valid Fortran 77 source code? Does it compile if you call it old_fortran.f90?
 

jasnw

macrumors 65816
Nov 15, 2013
1,012
1,048
Seattle Area (NOT! Microsoft)
OP, your posting was a bit confusing until I checked the thread you linked to over at StackOverflow. The "ld: warning:" you show was from an attempt to compile and link file hello.f77 and not old_fortran.f77 as shown in your post.

Anyway, it looks like you may have an install problem. The warning is from the loader (ld) and appears to indicate you may not have the gfortran built for use on OS X. Another issue might be that you don't have the correct command-line tools for Xcode installed (see https://gcc.gnu.org/wiki/GFortranBinariesMacOS ).
https://gcc.gnu.org/wiki/GFortranBinariesMacOS
Run
gfortran -v
to get version information and let us know what it shows.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,421
A sea of green
Anyway, it looks like you may have an install problem.
I don't think so. At the end of his StackOverflow thread the OP says:

Its working if I use
Code:
gfortran old_fortran.f -o a.out
This is consistent with my suspicions after reading the other StackOverflow posts.

I'm pretty sure the problem is simply the .f77 filename extension. Change it to one the compiler recognizes as being for Fortran source, and compilation should work.

Read the following to learn the compiler's recognized file extensions:

https://gcc.gnu.org/wiki/GFortranGettingStarted
By default, gfortran is aware of a few file extensions, and its action depends on the extension of the file you ask it to compile. Examples:

if the file is named code.f gfortran supposes it is fixed-form source, with no preprocessing needed.
if the file is named code.f90 gfortran supposes it is free-form source, with no preprocessing needed.
if the file is named code.F gfortran supposes it is fixed-form source and performs preprocessing.
if the file is named code.F90 gfortran supposes it is free-form source and preprocess it.
There are other extensions recognized, such as: .f95 is the same as .f90 and .F95 is the same as .F90​

http://fortranwiki.org/fortran/show/File+extensions
For older, fixed-form code, such as FORTRAN 77, the .f or .for extensions are typically used.​

Google search terms: gfortran file extension


Explanation

As noted, the error message is from the linker (ld). It outputs the first part of the file in hex form:
0x20 0x70 0x72 0x6F 0x67 0x72 0x61 0x6D 0x20 0x6D 0x61 0x69 0x6E 0x0A 0x0A 0x63​

Converted to displayable text, this is:
program main

c​

In other words, it's the start of a Fortran source file.

So the question is: why would the linker be getting a Fortran source file? Or phrased another way, why isn't the Fortran compiler compiling the source file, and passing the resulting object file to the linker?

The answer lies in the file extension. It's not recognized by the compiler as being a source-file extension. As a result, the compiler simply passes it along to the linker. This is a general rule among all GCC language compilers. Files are handled by different phases, and recognized by their file extension. Files are also passed transparently along by phases that don't recognize them, intended as input for subsequent phases. Since the linker is the last phase, it's the last point at which a file can be processed, and when the linker tries to process the Fortran source as some kind of library or object file, it fails.

The Fortran compiler's list of accepted Fortran-source file extensions can be read above. In the same way that 'gcc' won't know what to do with a ".c89" file extension, the Fortran compiler doesn't know what to do with a ".f77" one.
 

warriervineetha

macrumors newbie
Original poster
Jul 21, 2016
2
0
Canada
OP, your posting was a bit confusing until I checked the thread you linked to over at StackOverflow. The "ld: warning:" you show was from an attempt to compile and link file hello.f77 and not old_fortran.f77 as shown in your post.

Anyway, it looks like you may have an install problem. The warning is from the loader (ld) and appears to indicate you may not have the gfortran built for use on OS X. Another issue might be that you don't have the correct command-line tools for Xcode installed (see https://gcc.gnu.org/wiki/GFortranBinariesMacOS ).
Run
gfortran -v
to get version information and let us know what it shows.

Thank you for pointing out the filename difference. I have corrected it.
Here is the version:

Using built-in specs.

COLLECT_GCC=gfortran

COLLECT_LTO_WRAPPER=/usr/local/gfortran/libexec/gcc/x86_64-apple-darwin15/6.1.0/lto-wrapper

Target: x86_64-apple-darwin15

Configured with: ../gcc-6.1.0/configure --prefix=/usr/local/gfortran --with-gmp=/Users/fx/devel/gcc/deps-static/x86_64 --enable-languages=c,c++,fortran,objc,obj-c++ --build=x86_64-apple-darwin15

Thread model: posix

gcc version 6.1.0 (GCC)
[doublepost=1469220861][/doublepost]
I'm no fortran expert (I say that a lot these days...). Is old_fortran.f77 valid Fortran 77 source code? Does it compile if you call it old_fortran.f90?

Yes it is valid.
[doublepost=1469220930][/doublepost]Its working now with .f extension. Thanks for all the comments.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.