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

multiple names for a subroutine in a DLL?

jpnolan
Beginner
709 Views
I have a library of dozens of subroutines which I use from various applications: S-Plus, R, and Fortran/C code. These three can call a DLL directly. Unfortunately, R now requires a different calling convention (C and REFERENCE), whereas S-Plus and Fortran/C code use the Windows standard calling convention. Is there anyway to use the ATTRIBUTES directive to have one source program to do both? I've tried to get different entry points, with different calling specifications by using something like:

subroutine mysub(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT :: mysub
cDEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE :: mysub1
...

This doesn't work - only the first name 'mysub' appears in the DLL.

A complicating factor is that I have dozens of functions that I want to be exports in the DLL, and some of them are called internally from other parts of the library. When I eliminate the first ATTRIBUTES (manually or with a conditional compile), the second symbol 'mysub1' appears in the DLL, but other parts of the Fortran code now can't see mysub (they are looking for mysub@12).
I've experimented with the ALIAS attribute, but had no luck.

The only way I can see to do this is to make a second subroutine and give it the different calling specifications, but then have it call the first. For example,

subroutine mysub(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT :: mysub
...


subroutine mysubA(a,b,c)
cDEC$ ATTRIBUTES DLLEXPORT, C, REFERENCE :: mysubA
call mysub(a,b,c)
return
end


Then S-Plus and Fortran can call the DLL with name mysub using the standard calling sequence, whereas R can call the DLL with name mysuba and teh C calling convention. Of course, this leaves two sets of code to maintain. When there are tens of thousands of lines of code in a project and dozens of entry points, this becomes a headache.

I guess the R developers found it easier to NOT use the windows standard for calling DLLs, but it is a pain.
0 Kudos
2 Replies
Steven_L_Intel1
Employee
709 Views
I assume that by "Windows calling convention" you mean STDCALL.

Jacket routines are the only reasonable solution I can think of. You can use ATTRIBUTES ALIAS to give the jacket the external name expected.
0 Kudos
jpnolan
Beginner
709 Views
Yes, I meant STDCALL for "Windows calling convention".

I figured the "jacket" or "wrapper" routines were the only way to go. Since I have 79 of these entry points, I wrote a script to "parse" my fortran source files and automatically produce the wrapper function. A pain, but it works.

Thanks for your reply.
0 Kudos
Reply