Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26744 Discussions

Call Fortran DLL into another Fortran DLL

rizzo__rafaela
Beginner
137 Views

I need to call a function, e.g. func_private, from a private library at Fortran 90, IMSL, into my main code at Matlab. Then, I created a DLL file with a function that calls func_private. I specified everything as specified by https://docs.roguewave.com/en/imsl/fortran/current/common/readme.html. And, also, I created a header file in C++.

However, when I try to load my dll in Matlab as

loadlibrary example_dll.dll example_header.h alias lib

it gives me the following error message:

Error using loadlibrary
There was an error loading the library "<specified path>\example_dll.dll"
The specified module could not be found.
Caused by:
    Error using loaddefinedlibrary
    The specified module could not be found.

Apparently, this error occurs if you do not have all the necessary DLLs along with the one that you are using with the LOADLIBRARY function. This error is thrown if any of the dependent DLLs is missing.

Then, I tried to include the missing DLLs into my Fortran DLL, but I could not figure how to do this. An example of my code is described below.

 

Fortran Code (created as a DLL file):

DOUBLE PRECISION function rizzo_func(a, b, c)
!DEC$ ATTRIBUTES DLLEXPORT, ALIAS : "rizzo_func" :: rizzo_func
DOUBLE PRECISION a, b, c
EXTERNAL FUNC_PRIVATE

include 'link_fnl_shared.h'

CALL FUNC_PRIVATE(a, b, c)

rizzo_func = c

END FUNCTION

 

Header file, C++:

#ifdef __cplusplus
extern "C" {
#endif
	__declspec(dllexport) double rizzo_func(double* a, double* b, double* c);
#ifdef __cplusplus
}
#endif

 

Thanks for any help,

Rafaela Rizzo.

 

0 Kudos
1 Reply
Steve_Lionel
Black Belt Retired Employee
137 Views

Your Matlab loadlibrary reference makes no sense to me, and the syntax seems to be incorrect (based on the Matlab documentation I can find,)

Do I gather that you are using this method as a way of calling an IMSL routine from Matlab? You may find that this is a violation of the Matlib license agreement.

Yes, it is often the case that "module could not be found" is really that there are missing dependent DLLs, but it can also mean that the called routine isn't exported from the DLL by the specified name.

Reply