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

Calling C++ dll in a fortran program

shreyas_0291
Beginner
191 Views

Greeting,

A new poster here.

I am working with a C++ dll originally written for a finite element program. Because it is available open source, I decided to use it in my own FE program written in FORTRAN (.f90). 

I had mailed the developers about implementing their dll in my program and the advise that they gave me was to "create a standard C wrapper around the C++ class interface, and then call the standard C from FORTRAN".

I have been working with fortran for quite sometime now, but using an external dll is something new to me.

Would be really nice if someone could explain me what the wrapping of C++ class interface means and how it could be done.

Any help, pointer or links to tutorials to accomplish this task would be appreciated.

 

Best,

Shreyas

0 Kudos
1 Reply
Arjen_Markus
Honored Contributor I
191 Views

You need to inform the C++ compiler that you are using a C routine (well, actually a routine that uses the C conventions, but that is irrelevant). The way to do that is:

extern "C" {

.... interface to the routine

}

There should be plenty of tutorials on the Internet to help you with further details.

The fact that the routine has to be in a DLL is not relevant to this. That is merely a matter of linking the Fortran library with the right options. I advise you to use the ISO_C_BINDING feature to make sure that the Fortran routine can be correctly called from C (and with the above, from C++). 
 

0 Kudos
Reply