PDA

View Full Version : Calling Borland C++ DLLs from Fortran


a.pereira
07-07-2004, 06:13 PM
Hi all.

I'm newbie in Fortran (I always will be) and appreciate that someone give me an answer to my question: is it possible to invoke C++ classes from Fortran code? If so, how can I do that and what version of Fortran compiler will be compatible with Borland C++Builder 3 or later?

I explain:
I have an application built in Borland C++ Builder 3 with several DLLs. Each DLL represents a C++ class. Some of the DLLs must be able to be called by Fortran legated programs. The intention is upgrade the Fortran program with the funcionalities given by the new C++ classes. I have a free Fortran 77 compiler but, until now, I couldnīt make the code working.

Can anyone help me?
Thanks a lot.

tzeis
07-08-2004, 04:41 PM
This is usually not possible, because Fortran 95 does not provide a mechanism for interoperating with C++ classes. You would need to create C wrappers that could be called by Fortran. If you want to move to .NET, and use managed C++, and Fortran for .NET, then interoperation is possible, you could use C++ class objects in your Fortran for .NET code.

a.pereira
07-15-2004, 03:34 PM
Ok, if I understood well I have to create C wrappers that can be invoked by Fortran statically. Is that right? (The migration for .NET platform is, in this moment, not possible)

Assuming that DLLs (with the C++ classes and wrappers) were built by Borland C++ Builder 3, is it possible to invoke them from Fortran programs using Lahey Fortran 95 (linking Fortran program with those DLLs)?

It's important the answer because if it's possible I'll buy the Lahey Fortran 95.

tzeis
07-15-2004, 04:46 PM
You would probably have to call the wrapper through a DLL, because LF95 sits on the Microsoft C runtime, and there might be conflicts if you try to static link with both the Microsoft and Borland C runtime libraries. We ship example code with the compiler showing how to interoperate with Borland C DLLs.