G95: just say no to second underscore

When code is being generated by a C compiler to be called by Fortran programs, as in the netCDF F77 interface, we have to worry about the Fortran compiler's name mangling. The G95 documentation describes its default behaviour thus: "G95 follows the f2c convention of adding an underscore to public names, or two underscores if the name contains an underscore." The other commonly used compiler that follows this convention is G77 (but its Gnu successor Gfortran just uses a single underscore).

The f2c one/two-underscore behaviour is rather difficult to handle, as I found out when trying to build the MITgcm ocean model, see here:

http://forge.csail.mit.edu/pipermail/mitgcm-support/2006-October/004374.html

So I have decided to become 100% second-underscore-free. To do this I had to rebuild netCDF. Here is the necessary configure statement (used successfully with 3.6.2-beta4 on Linux, Cygwin and MSYS+MinGW):

CC=gcc FC=g95 CPPFLAGS=-DpgiFortran FFLAGS=-fno-second-underscore FCFLAGS=-fno-second-underscore ./configure

If you get it wrong, "make" completes OK, but "make test" fails when testing the Fortran code.

Why am I sharing this with the group? Partly for posterity (AKA Google searches). But I have three questions/comments:

1. Perhaps this could be made the default? It would break G77 compatibility and cause a bit of confusion in the short term, but in the long term I think we would all be better off.

2. I have to set both FFLAGS and FCFLAGS? Why? Surely one would do.

3. I note that the configure script reports (for example): "checking for C-equivalent to Fortran routine SUB... sub_". I haven't looked at the configure code, but I assume it is trying different C names (sub, sub_, SUB, etc) until it gets the right one. The subroutine/function names in the netCDF-3 F77 interface all have underscores. So why not do the test with a name that includes an underscore? Then the f2c name-mangling could be handled automagically?

--
Mark Hadfield          "Kei puwaha te tai nei, Hoea tahi tatou"
m.hadfield@xxxxxxxxxx
National Institute for Water and Atmospheric Research (NIWA)



==============================================================================
To unsubscribe netcdfgroup, visit:
http://www.unidata.ucar.edu/mailing-list-delete-form.html
==============================================================================


  • 2006 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: