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

Calling Subroutine from Within DLL

Mark_Gracey
Beginner
895 Views
I have recently been developing a DLL in Intel Visual Fortran.
It needs to be called from both Fortran and VB6.
So far, so good.

I am now attempting to call one of the subroutines (EPILOG)from another subroutine in the DLL (CALC_ATMOS).
When I try to build the DLL I get the following link error:
error LNK2019: unresolved external symbol __imp__EPILOG referenced in function Calc_Atmos.

Can anyone see what I have done wrong?

I have attached both Calc_Atmos.F90 and Epilog.F90.

Thanks,

Mark.



0 Kudos
1 Solution
anthonyrichards
New Contributor III
895 Views
Try adding

INTERFACE
SUBROUTINE EPILOG(EXIT_CODE)
!DEC$ ATTRIBUTES STDCALL, REFERENCE, ALIAS:'Epilog' :: Epilog
INTEGER EXIT_CODE
END SUBROUTINE
END INTERFACE

to the calling subroutine or, better, put it into a module (with all your other
INTERFACE blocks) and then USE the module wherever you reference a routine or function that needs
an interface block.

View solution in original post

0 Kudos
4 Replies
anthonyrichards
New Contributor III
895 Views
If you compile them seperately from two seperate files, you have to add an interface block for subroutine epilog to the calc_atmos.f90 file so that the compiler knows what epilog is when compiling calc_atmos. Otherwise, combine the two files into one and then I think the compiler with naturally obtain the information it needs.

Also, if the two routines are in the same DLL, I don't think you need the DLLIMPORT directive.
0 Kudos
Mark_Gracey
Beginner
895 Views

Anthony,

Thank you for that.

However, being new to this approach to software, I think I may be missing the point.
I thought that the !DEC$ATTRIBUTES lines were the interface block.
Are you saying that I need other commands in addtion to(or instead of) these lines.

Unfortunately, I cannot combine the two files, because, Epilog will be called from every routine in the DLL.
In any case this is just the simple start to a much more complicated file structure.
I was trying to start with an easy case, but fell over at the first hurdle.

When I remove the DLL directive, I get a different link error:
error LNK2019: unresolved external symbol _EPILOG referenced in function Calc_Atmos.

Thanks again for your help - I really appreciate you taking the time.
Unfortunately, I'm not totally on top of this subject yet, and need a little more pointing in the right direction,

Mark.


0 Kudos
anthonyrichards
New Contributor III
896 Views
Try adding

INTERFACE
SUBROUTINE EPILOG(EXIT_CODE)
!DEC$ ATTRIBUTES STDCALL, REFERENCE, ALIAS:'Epilog' :: Epilog
INTEGER EXIT_CODE
END SUBROUTINE
END INTERFACE

to the calling subroutine or, better, put it into a module (with all your other
INTERFACE blocks) and then USE the module wherever you reference a routine or function that needs
an interface block.
0 Kudos
Mark_Gracey
Beginner
895 Views

Anthony,

Thank you.
It's working perfectly now.

Sorry that you had to spell it out precisely, but this is new technology for me and I'm still learning.

That's twice you've bailed me out - I appreciate it,

Mark.
0 Kudos
Reply