Hello,
I am trying to call procedures defined in a module in a dll that I created myself. I am mostly following the instructions that I found here. In particular, for 'simplicity' purposes, I am trying to avoid using the !DEC$ ATTRIBUTES DLLIMPORT in the main. Indeed, I thought that the process described in the link above for sharing data through modules could work with procedures. And most times it does.
My problems comes when I call a routine whose arguments' dimensions are contained in another module in the library (the main, outside the library, calls a subroutine which is in a module in the library, and uses another module of the library for dimensions). In those cases, the compiler tells me that the constants used for the dimensions are unresolved symbols in the main. But they are NOT USED in the main. To be clearer, I included a MWE that reproduces the problem:
The following are the two modules compiled in the dll:
MODULE constantsMod integer :: nStates end MODULE MODULE testMod contains subroutine setupConstants(nIn) !DEC$ ATTRIBUTES DLLEXPORT, ALIAS : "setupConstants" :: setupConstants use constantsMod implicit none integer, intent(in) :: nIn nStates = nIn end subroutine subroutine test(nX, nY) !DEC$ ATTRIBUTES DLLEXPORT, ALIAS : "test" :: test use constantsMod implicit none real*8, intent(in) :: nX(nStates) real*8, intent(out) :: nY(nStates) print*, nX, nStates nY = nX end subroutine subroutine test2(nStates, nX, nY) !DEC$ ATTRIBUTES DLLEXPORT, ALIAS : "test2" :: test2 implicit none integer, intent(in) :: nStates real*8, intent(in) :: nX(nStates) real*8, intent(out) :: nY(nStates) print*, nX, nStates nY = nX end subroutine end MODULE
The main is compiled on its own (and marked to be dependent on the library in Visual Studio: the library and the main are two projects in the same solution, with the same output directory so that the dll is in the same folder as the exe), and is as follows:
PROGRAM main use testMod implicit none real*8 :: nX(6), nY(6) CALL setupConstants(6) CALL test(nX, nY) CALL test2(6, nX, nY) end program
When compiling the previous main, I get: "Error 1 error LNK2001: unresolved external symbol _CONSTANTSMOD_mp_NSTATES main.obj "
When commenting out the call to test and leaving test2, no problem. If I stop using testMod and add three !DEC$ DLLIMPORT, no problem either. However, because in my real project I have MANY functions being exported and I'd love to not have to DLLIMPORT all of them.
Now, I understand that the reference I cited above only mentions sharing DATA through modules, and not procedures. I am also expecting the problem to come from the interfaces that are generated by the module. I was just wondering if there was a workaround that didn't involve writing the many DLLIMPORT statements I would need.
Thanks!