Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

DLLEXPORT and Interface blocks

fsharpminor
Beginner
1,233 Views
Bit of a newbie question on F90 as I've not really worked with interface blocks before.

I can't seem to export a routine that has an interface specification to it. Example (cut down from the original problem) is:

module foo

interface fred
module procedure bar
end interface

...

contains

subroutine bar
!dec$attributes dllexport,alias:'myname'::bar
...
end subroutine bar

end module

This will compile ok but will not export the symbol 'myname'. However, if the interface block is removed, then it will export it. Nothing seems to work by putting the dllexport attribute in the interface block either.

The only way it will work is if I have a separate glue routine that does not have an interface specified, & which calls the required routine.

Is there any neater way around this?

Regards,
FSM
0 Kudos
10 Replies
Jugoslav_Dujic
Valued Contributor II
1,233 Views
Sounds like compiler bug to me. Steve?

Few workarounds to try:
1) Create a .DEF file with the following contents & just insert it into your project:
EXPORTS
myname=_FOO_mp_BAR@0
where FOO is module name (uppercase), _mp_ is lowercase, BAR routine name, and @n stands for 4* number of arguments of BAR (every CHARACTER(*)argument, if any, counts as two).

2) What happens if you dllexport fred instead of bar?

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
1,233 Views
I know this works in the current compiler, as I've done it. I'm not sure if it works in 6.6B. What version is being used here?

Exporting bar is correct, but the use of the alias here may cause trouble for users of module foo (I haven't tried this part).

Of course, this is now outside of "F90", which has no concept of "dllexport".

Steve
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,233 Views
I was just working on a dll project on 6.6B, so I performed a quick test and I can confirm it doesn't work. Linking is all OK, but no export is produced if there's an interface.

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
1,233 Views
Ok - I guess that's a bug we fixed post-6.6B.

Steve
0 Kudos
fsharpminor
Beginner
1,233 Views
I'm using 6.6B.

Is there any possibility of getting the bug fixed version?
0 Kudos
fsharpminor
Beginner
1,233 Views
Jugoslav wrote:

2) What happens if you dllexport fred instead of bar?

The compiler doesn't allow a DLLEXPORT attribut to be attached anywhere in the interface block & merely complains that the line is wrongly positioned.

regards,
FSM
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,233 Views
Yep, I tried that myself. But I've also verified that approach with .DEF file does work.

Jugoslav
0 Kudos
gfthomas8
Novice
1,233 Views
> I've also verified that approach with .DEF file does work.
>
> Jugoslav

Yes. I've been dllexporting from within interfaces for years now without any problem because I always create a .def for the dll exports.

Ciao,
Gerry T.
0 Kudos
gfthomas8
Novice
1,233 Views
Even with .def entry for clearfp, the following doesn't link because clearfp is unresolved:

interface
integer(4) function clearfp() ![C,ALIAS:'__clearfp'] ()
!DEC$ ATTRIBUTES DLLEXPORT, C, ALIAS:'__clearfp':: clearfp
end function clearfp
end interface

If I eliminate !DEC$ and the comment in the function statement, it links but doesn't export. How do I fix this?

Thank you,
Gerry T.
0 Kudos
gfthomas8
Novice
1,233 Views
For anyone who might be interested, with a .def entry for _clearfp, the following allows clearfp to be referenced within Fortran code and for it to be exported as _clearfp:

interface
integer(4) function clearfp()[DLLEXPORT, C, ALIAS:'__clearfp']()
end function clearfp
end interface

It's all much ado about using a single (_), a double (__), or no underscore really and exporting from an interface block without the !DEC$ metacommand (but I'm sure it's lurking somewhere.)

HTH,
Gerry T.
0 Kudos
Reply