PDA

View Full Version : Can gcc use LF95 Linux module program units?


R. T. (Fortran Man)
09-03-2003, 05:34 PM
I compiled a *.f90 module, and I am trying to call routines in this module from a *.cc code.

The problem is that the name mangling used by Lahey incorporates a "." (e.g., routine foo in module mymod, generates a symbol mymod.foo_). Unfortunately, the presence of the "." prevents compilation of the *.cc code at the declaration
statement:

extern "C" {
int mymod.foo_();
}

Lahey Support
09-03-2003, 05:43 PM
The name mangling used by LF95 can not be changed.

To access the module routine create a wrapper function in the Fortran source for the routine and use this wrapper in the C source.

In this example testmod.myfunc can not be used in the C main but the function extfunc is available.


module testmod

contains

integer function myfunc()
myfunc = 5
return
end function myfunc

end module testmod

integer function extfunc()
USE testmod
extfunc = myfunc()
end function extfunc


MAIN__()
{
long int extfunc_();
long int j;
j = extfunc_();
printf("%d\n", j);
}