FORTRAN calling C PGI Visual Fortran

Using PGI Visual Fortran and Visual Studio 2010

Both projects are in the same solution.

Fortran static library has:

SUBROUTINE FOO(filename)
  EXTERNAL init_www
  ...
  CALL init_www_(filename)
  END

C program has:

void init_www_(char *filename);

This is what the documentation in pgiug.pdf Chapter 12 pg 161 Example 12.3 says to do.

However, I can only get this to link if I use

CALL init_www(filename)

and not using

CALL init_www_(filename)

Is the documentation wrong in saying to use the CALL statement with an appended underscore for the C function?

Hi initialzero,

This appears to be a typo. The Fortran code should not have the trailing underscore. By default, Fortran routines names are appended with an underscore to avoid name conflicts with C routines.

Note, if you are using Win32, you may need additional changes or flags since Win32 can use varying calling conversions. See the last section in Chapter 12 “Win32 Calling Conversions for details”.

  • Mat