How does one package a derived type with type-bound procedures into a dynamic-link library (DLL)? Specifically, what all does one needs to include in the system-definition (DEF) file for EXPORT definitions?
Say I have a module with a public derived type with one public type-bound procedure. Also, say this derived type includes several other private type-bound procedures as well as private variables that are of other derived types. And say the public type-bound procedure calls other private type-bound procedures within the same type as well as it makes use of other private derived types and their private type-bound procedures. If I want to package this all into a DLL, what all do I need to include in the EXPORTS section of the DEF file for the linker?
In the above, private and public refer to attributes of Fortran module elements and their scope as defined by PRIVATE and PUBLIC statements. Note I do appreciate the fact that the requirement for export definitions of symbols in a DLL is totally different from these Fortran module-scope attributes. I’m simply bringing up a situation where a contrived connection exists.
In my project for a caller (i.e., a main program that is supposed to invoke the above-mentioned DLL at run-time), the linker input includes a LIB file corresponding to the DLL. The linker, however, throws "error LNK2001: unresolved external symbol" messages unless I include EXPORT definitions in the DLL DEF file for every type-bound procedure that the public type-procedure calls, whether directly or indirectly. (For those of you who use compiler directives (!DEC$) instead, it is as if ATTRIBUTES DLLEXPORT needs to be specified for every procedure that is called by the public type-bound procedure). Is this only to be expected? Or am I missing something in my setup?
Consider an example:
MODULE MyMod USE OtherProcsMod, ONLY : OtherProc1, OtherProc2 PRIVATE TYPE, PUBLIC :: MyPubType PRIVATE INTEGER :: MyInt REAL :: MyReal CONTAINS PRIVATE PROCEDURE, PASS(This) :: PrivProc1 PROCEDURE, PASS(This) :: PrivProc2 !.. PUBLIC PROCEDURE, PASS(This), PUBLIC :: PubProc END TYPE MyPubType CONTAINS SUBROUTINE PubProc(This, Arg1, Arg2) .. .. CALL This%PrivProc1(Arg1) .. CALL This%PrivProc2(Arg2) END SUBROUTINE PubProc SUBROUTINE PrivProc1(This, Arg1, Var1) .. .. CALL OtherProc1(Var1) .. END SUBROUTINE PrivProc1 SUBROUTINE PrivProc2(This, Arg2, Var2) .. .. CALL OtherProc2(Var2) .. END SUBROUTINE PrivProc2 END MODULE MyMod
In my case, it is as if the linker expects DLLEXPORT definitions for PrivProc1, PrivProc2, etc. as well as OtherProc1, OtherProc2, etc.
Note if one were to create a DLL for set of FORTRAN-77 procedures and if only subroutine PubProc was needed by callers, then one only needed to the export definition for it in the DEF file. The linker for a main program that call such as DLL is satisfied with a LIB file with the symbol definitions of PubProc. So what is different with derived type procedures? I think I am missing something due to my rather limited understanding of type-bound procedures, linker requirements, and so on.
Thanks much in advance,