Using g77 to compile Fortran library on 64bit system

Posted on 2006-03-28
Last Modified: 2013-11-08

I've encountered a problem compiling a library written in Fortran and C on a 64bit system. I've tested the library on a 32bit system and it is running fine, so the problem must be with how I compile it on a 64bit system, details: gcc 3.4.5 Suse 9.

The flags used to compile on 32 bit system are:

#gcc flags
#g77 flags

I have modified it for 64bit compilation by adding

-m64 to both CFLAGS and FFLAGS, the library still compiles but calls to some of its functions result in Segmentation fault.

After some playing around I discovered that adding an additional optimization flag -O3 solves some of the problems, that is some functions begin to work but eventually the thing still crashes.

If anyone can provide a proper procedure to compile under 64bit system that would help a lot.

Thank you!

Question by:alex123
    LVL 22

    Accepted Solution

    There could be some 32-bit dependencies in the original code.  For example if some variables are declared as INTEGER * 4 in one common block, but as INTEGER in a supposedly parallel block, then the code would compile and work fine if the default integer is 32 bits, but will cause major kabooms if INTEGER becomes 64 bits.  

    I'd look over all the parameters and common blocks to see if there might be some mismatches.

    Also be wary of any library routines or precompiled routines you call-- they all have to be 64-bit compatible.


    Author Comment

    grg9 thank you!

    I have a followup question to the original one. It seems that even on a 64bit system fortran's INTEGER type remains INTEGER*4 and not INTEGER*8. The library I am compiling might be suffering from this since it intefraces with some C code of its own and because of this the types passed between C and Fortran code no longer match. For my purposes I would also prefer to have all INTEGER types be equivalent to INTEGER*8. It there any way to force g77 to compile the library with INTEGER=INTEGER*8 instead of INTEGER*4?

    Thank you
    LVL 22

    Expert Comment

    >It there any way to force g77 to compile the library with INTEGER=INTEGER*8 instead of INTEGER*4?

    I don't see any option for that!  

    You may be able to do it by adding IMPLICIT INTEGER * 8 ( I-N )  everywhere.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The viewer will learn how to implement Singleton Design Pattern in Java.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now