Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.

Compile C dll calling a Fortran dll

ghylander
New Contributor I
568 Views

I'm unsure if this should lie in this or the Fortran forum.

I want to compile a C dll, Load-Time linking it to a Fortran dll to use a certain function. The C dll is then run by a software.

What happens is that when I run the software, it states "The dynamic library could not be loaded. Check that the file exists in the specified location and that it is compiled for 64-bit applications." USing dumpbin /headers I verified both the Fortran and C dll are compiled for 8664 machine. If I remove the call to the Fortran dll function, the C dll can be loaded and run with no problems.

 

I have followed all indications I could find:

In the Fortran code:

I use BIND(C, NAME) in the function I want to call from the C script

I declare !DEC$ ATTRIBUTES DLLEXPORT :: SUBRNAME

I declare USE, INTRINSIC :: ISO_C_Binding

I use C compatible var types in the Fortran code for interfacing with C

I use the /dll option when compiling

 

In the C code:

I have a headers file with the functions I export from the C dll, and the function I import from the Fortran dll. Imports and exports use __declspec(dllimport) and __declspec(dllexport) accordingly

I pass variables as pointers when calling the Fortran dll function

I added the Fortran dll associated lib object to the linker as additional dependency

 

When I run dumpbin /exports on the fortran dll, the function I wish to export is listed.

Similarly, when I run dumpbin /imports on the C dll, it shows it's expecting to import the function from the Fortran dll

 

As additional information, I call the Fortran dll from within a Function I'm exporting from the C dll. So main software calls function from C dll, C dll calls function from Fortran dll, with the Fortran dll function prototype being declared in a headers file. Of course the headers file is linked too.

Labels (2)
0 Kudos
1 Solution
ghylander
New Contributor I
458 Views

Managed to solve it, issue simply was that I was placing the Fortran dll in the same dir as the C dll, and instead the Fortran dll needed to be in the same dir as the exe calling the C dll

View solution in original post

3 Replies
MadhuK_Intel
Moderator
476 Views

Hi,


Thank you for posting in Intel communities.


Could you please provide a complete reproducer code and steps to reproduce at our end?


Please provide the below-mentioned details to investigate your issue

1.   Intel Compiler details you are using to compile the C DLL and Fortran DLL

2.   Platform details you are working on


Thanks and regards,

Madhu


ghylander
New Contributor I
459 Views

Managed to solve it, issue simply was that I was placing the Fortran dll in the same dir as the C dll, and instead the Fortran dll needed to be in the same dir as the exe calling the C dll

MadhuK_Intel
Moderator
404 Views

Hi,


Glad to know that your issue is resolved. Thanks for sharing the solution with us. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Best regards,

Madhu


Reply