Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

Compile C dll calling a Fortran dll

ghylander
New Contributor I
1,014 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
904 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

0 Kudos
3 Replies
MadhuK_Intel
Moderator
922 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


0 Kudos
ghylander
New Contributor I
905 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

0 Kudos
MadhuK_Intel
Moderator
850 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


0 Kudos
Reply