Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

One subroutine calling another subroutine within a Fortran DLL

Ian_Smith
Beginner
1,581 Views

In the past I have written Fortran software, compiled it into a DLL using Compaq Visual Fortran and been able to call the DLL from Microsoft Excel without any problems. I would now like to be able to do the same thing again but using Intel Visual Fortran (Microsoft Visual Studio) to compile the DLL.

The software consists of about 40 subroutines, of which 6 are to be "visible" from the DLL. A potential complication (I think) is that one of these visible 6 subroutines is also called from within another one of the visible 6.

After reading other documentation and threads, I have replaced the basic
!DEC$ ATTRIBUTES DLLEXPORT :: SUBROUTINE1
statement, used when compiling using Compaq Visual Fortran, with the statement
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUBROUTINE1" :: SUBROUTINE1,
and also included statements such as
!DEC$ ATTRIBUTES REFERENCE :: PARAMETER1
where there are non-array output parameters.

When I try to compile using Intel Visual Fortran, I get an error message of the form
error LNK2019: unresolved external symbol _SUBROUTINE2 referenced in function SUBROUTINE1.

I'm wondering if anyone has tried to do something similar and has some advice or if there is simply something obvious that I am missing. (I don't have any problems creating a DLL that can be called from Excel in the case where there is no interaction between the subroutines.)

Thanks

0 Kudos
3 Replies
Steven_L_Intel1
Employee
1,581 Views
The problem is that when you call SUBROUTINE1 from elsewhere in the DLL, it is looking for an external name _SUBROUTINE1, but since you have ALIAS, it is actually "SUBROUTINE1". Offhand, I would have expected a similar problem in CVF.

To fix this, add:

!DEC$ ATTRIBUTES STDCALL, REFERENCE, ALIAS:"SUBROUTINE1" :: SUBROUTINE1

in the sources where you call SUBROUTINE1. Add similar directives for other internal routines you call.
0 Kudos
Ian_Smith
Beginner
1,581 Views

Thanks for your help, Steve. Where appropriate I added the statement as you suggested and was able to compile the software successfully.

I then encountered another problem (for which I haven't been able to find a solution despite quite a lot of searching). In Microsoft Excel, when I press the button to call the VBA code, no results are written to the spreadsheet. If I place a breakpoint in the VBA code and step through it, the DLL is called successfully and the expected results are written to the spreadsheet.

When I run Dependency Walker on the DLL, IESHIMS.DLL and WER.DLL are reported as being missing, but from reading other threads Isuspect thatthis is not a major problem.

Have you previously encountered this difference between calling a DLL in Microsoft Excel "normally" and in debug mode?

0 Kudos
Steven_L_Intel1
Employee
1,581 Views
IESHMS.DLL and WER.DLL can be ignored.

I have not seen an issue with Excel calling a Fortran DLL in debug mode.
0 Kudos
Reply