Converting an Intel Style preprocessor to work with gfortran

The source code I'm working with was originally written for the Intel Fortran compiler, so it has preprocessor directives like !DEC$ATTRIBUTES DLLEXPORT::MYDLL
!DEC$ATTRIBUTES STDCALL::MYSUBROUTINE
!DEC$ATTRIBUTES ALIAS: 'MYENTRYPOINT'::MYSUBROUTINE

How do I convert this to work with gfortran. Basically, I want to be able to define and specify entry points. Right now, when I compile with gfortran, each routine becomes open as an entry point. In addition, the entry point name is lowercase with an underscore at the end.

+4
source share
2 answers

If you put your routines in the module and place the PRIVATE statement at the beginning of the module, then PUBLIC :: name1, name2, only the procedures name1 and name2 will be visible outside the module. This should go through the library into which you put the object code containing the module. This is supported with Fortran 90.

As @janneb already answered, you can use the bind (C, name = X) approach to fully control the externally visible name of the procedure by overriding the name of this procedure in Fortran. This is part of Fortran 2003 and has been supported by many compilers for many years. A possible problem with the bind (C) approach is that it indicates that the calling convention of the routine should be equal to C. If this is different from this Fortran and you want to call these routines from Fortran, the complexity increases. Then you will need to specify an interface to inform the Fortran calling routines that they are calling, which is similar to routine C. Since people rarely care about the name visible to the linker, unless they call from C, may you need a C-call convention?

Examples in Private Function in Fortran and C / C ++, FORTRAN, Underscore, and GNU Autotools

+6
source

Source: https://habr.com/ru/post/1389295/


All Articles