libg2c

Hi,
How are you?
I use a code which uses g77 as a fortran compiler and uses -lg2c as a fortran C linker.
My question is: Is it possible to specify pgf77 as the fortran compiler and what is then the equivalent to -lg2c option.

thank you very much,

hhegab

Hi hhegab,


pgf77 can be used in place of and is compatible with g77. We do have a flag “-g77libs” which adds all necessary g77 libraries, including “-lg2c” to the link line. However if you prefer, since “-lg2c” is a library, it can simply be added to the link line.

Note that g77 adds two underscores to the end of function names while pgf77 only adds one. If you mix g77 and pgf77 compiled objects, you may need to add the flag “-Msecond_underscore” to the pgf77 compilation line to instruct pgf77 to use two underscores instead of one.

  • Mat

Hi,
thanks for the reply.

Do you mean I can use -g77libs instead of -lg2c?
I shall try what you said to see what shall happen?

hhegab

Do you mean I can use -g77libs instead of -lg2c?

Yes. “-g77libs” adds the appropriate g77 libraries for you. Some systems use “-lf2c” instead of “-lg2c” so using “-g77libs” is more portable since it will select the correct library for your system.

  • Mat

Hi,

Thanks for your reply, and sorry for the late answer.
I have tried the solutions you told me, but neither of them did work. May be because their path is not defined. How may I defined the path?

thanks.

Hi hhegab,

If libg2c.a is installed, it should be in /usr/lib or /usr/lib64 which are added to the link path automatically. So I doubt it’s a path problem. What’s the error message your getting?

  • Mat

Hi,

The error message I get is the following:

C-Fortran linking …failed,
-lg2c does not exist.

I use FC4 which uses gcc3.4. As you may know, this compiler does not contain g77 nor f77.
libg2c.a also is not contained. I use a package which needs g77 for compiling and linking to C codes some other fortran codes.
I thought that pgf77 may replace g77 (as you said, it does).

So, concerning FC4, could pgf77 replace g77 with all the needed libraries?


hhegab

Hi hhegab,


“-lg2c” is only needed when part of your code, such as from a library, has been compiled with g77. g77 requires libg2c since g77 converts your program from F77 to C (g2c) and needs a special set of routines to support this. If you are only using pgf77, then you do not need libg2c or the “-g77libs” flag since pgf77 is a “native” Fortran compiler.

Sorry for the confusion. I thought your orignial message meant how do I use pgf77 and g77 together not how can I replace g77 with pgf77.

  • Mat

Thank you very much for your concern.
I know I have caused you some trouble. But it is clear now.
The code I use, calls g77 to compile some fortran codes that comes with it. It asks for the libg2c to compile some of the fortran codes.
I have changed the fortran compiler option from g77 into pgf77, but it kept asking about libg2c. Now I understand that it wont be needed by pgf77.

Well, I can give you the code to try it if this may help you.

Thank you for your time,

hhegab

It’s not problem. I’m glad to help.

It sounds like your build process is putting “-lg2c” on the link line? How are you building your app? Do you use make? Configure? Some other method? It may be as easy as removing “-lg2c” from a Makefile.

  • Mat

Hi,

Thanks for the answers.
I use a script file to build the code, the script comes with the code and it uses make in its commands.
I dont know how may I send you the code, is there a way to do it?

hhegab

Hi hhegab,

You most likely need to just edit your script and remove or comment out the reference to “-lg2c”. While I can look at it, I’d like you try editing your file first.

If it’s small (< 100kb) you can send a gziped tar package to trs@pgroup.com and ask Dave to forward it to me.

  • Mat

I have changed the option as you said, and again, I was given the same error.
I have changed the compiler to be pgf77 and commented the option -lg2c but had the same error.
I used the above email to send the code.
Thank you very much for walking with me through all these troubles,

hhegab

Hi Hakim,

I got your code and was able to get it compile and run by updating your Linux configuration section in the “makeCC” file to:

Linux) CC="pgcc -fastsse" 
       F77="pgf77 -fastsse"
       lFort=-pgf77libs
       lDL="-Ddynamic -ldl"
       RANLIB=ranlib
     ;;

The issue was that your using the C compiler to link, in which case you need to link in the f77 runtime libraries, i.e. -pgf77libs (or -pgf90libs if using pgf90). Be sure to remove the “lFort” file and create a “tmp” directory.

  • Mat

Thank you, it compiled OK yet I still can’t make it work, but I believe I have consumed good deal ot time and space.

Thanks again,

Hatim