Showing results for 
Search instead for 
Did you mean: 

Calling C++ dll in a fortran program


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.




0 Kudos
1 Reply
Valued Contributor II

You need to inform the C++

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