Fortran 77 compiler issue

Discussion in 'Mac Programming' started by warriervineetha, Jul 21, 2016.

  1. warriervineetha, Jul 21, 2016
    Last edited: Jul 22, 2016

    warriervineetha macrumors newbie

    Jul 21, 2016
    I have an issue on mac os x El Capitan with Xcode 7. I'm using fortran 6.1, downloaded from 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:
  2. cqexbesd macrumors regular

    Jun 4, 2009
    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?
  3. jasnw macrumors 6502

    Nov 15, 2013
    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 ).

    gfortran -v
    to get version information and let us know what it shows.
  4. chown33 macrumors 604

    Aug 9, 2009
    I don't think so. At the end of his StackOverflow thread the OP says:

    Its working if I use
    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:
    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​
    For older, fixed-form code, such as FORTRAN 77, the .f or .for extensions are typically used.​

    Google search terms: gfortran file extension


    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


    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.
  5. warriervineetha thread starter macrumors newbie

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

    Using built-in specs.



    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)
    --- Post Merged, Jul 22, 2016 ---
    Yes it is valid.
    --- Post Merged, Jul 22, 2016 ---
    Its working now with .f extension. Thanks for all the comments.

Share This Page