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

DLLEXPORT overloaded interface.

Ilie__Daniel
初學者
1,537 檢視
Hello!

In a DLL I have code that performs real and complex number addition.
I put the two subroutines (real and complex addition) in a module and overloaded the interface.
The problem is that I want to export only one routine, i.e. the overloaded interface.

I included the code below:
moduleoutput
implicitnone
private

public::add
 
 
!dec$attributesdllexport,c,reference,alias:'add'::add
interfaceadd
moduleprocedureradd,cadd
endinterfaceadd

contains
 
subroutineradd(a,b,x)
implicitnone

real,intent(in)::a,b
real,intent(out)::x

x=a+b

endsubroutineradd
 
subroutinecadd(a,b,x)
implicitnone

complex,intent(in)::a,b
complex,intent(out)::x

x=a+b

endsubroutinecadd

endmoduleoutput

How do I export the overloaded interface "add"?

Thank you for your suggestions.
0 積分
5 回應
Steven_L_Intel1
1,537 檢視
You don't - that's not how it works. Your module makes "add" the only public symbol for users of the module. But you must export from the DLL all of the specific routines that "add" can resolve to. "add" is not a callable routine, it's a generic interface that the compiler sorts out.
Ilie__Daniel
初學者
1,537 檢視
Ok. Thank you Steve.
I exported each routine individually and added this to the main program:
interfaceadd
subroutineradd(a,b,x)
!dec$attributesdllimport,c,reference,alias:'radd'::radd
!dec$attributesreference::a,b,x
implicitnone

real,intent(in)::a,b
real,intent(out)::x
endsubroutineradd
 
subroutinecadd(a,b,x)
!dec$attributesdllimport,c,reference,alias:'cadd'::cadd
!dec$attributesreference::a,b,x
implicitnone

complex,intent(in)::a,b
complex,intent(out)::x
endsubroutinecadd
endinterfaceadd

Everything works fine now.
Steven_L_Intel1
1,537 檢視
If you used a module for your routines, just USE the module in the main program. You should never have to repeat the interface. The DLLEXPORTs will magically turn into DLLIMPORTs on the USE.
Ilie__Daniel
初學者
1,537 檢視
Ok, but this works only if I include the path to the compiled module file (output.mod). This is in addition to referencing the .lib in the main program, which I did before anyway.
Steven_L_Intel1
1,537 檢視
Yes - typically you would provide the LIB and MOD to the user of your code. If you make the library project a dependent of the main project, the compiler will see the .mod file from the library automatically (that is new in Composer XE 2011).
回覆