Help on C++/Fortran Mixed Programming using Visual Studio

Thread Starter

paco

Joined Feb 20, 2008
2
Does anyone know how to create/build a project in Visual Studio 2005 that includes subroutines written both in C++ and Fortran?
I got the Intel Fortran Compiler Ver 10.1 (which is not supported by VS 2008 yet)
I need to learn how to call a C++ subroutine from a Fortran program. At this point I don't have specific codes, my question is more general.
Any help or reference is appreciated.
 

Mark44

Joined Nov 26, 2007
628
Paco,

Disclaimer: It's been a long while since I did any mixed language programming...

In order for your Fortran code to call a function/method in a C++ module, the Fortran code needs to know the name of the function. Because functions/methods can be overloaded in C++, you need to know the name that the VS compiler generates (the "mangled" name) for the function. Different compilers mangle names in different ways, but the names for the functions usually have prefix or suffix information that encodes the number and types of parameters. That's how the compiler knows to call the right overload of foo when there are multiple foo overloads.

Can you use the VS debugger, in diassembly mode, to find out the compiler's name for the function? I'm guessing it would also include information about the class, if the function is a method on a class.

As far as the build process goes, I think you will need to use VS to compile the C++ code to object code (.obj) or maybe a DLL, compile your Fortran code with your IBM compiler, and then use the IBM linker to produce an executable.

Sorry I can't be more specific, but as I said, it's been a good long while since I've done any of this. I hope the information I've provided is helpful to you, and that you are able to fill in the gaps and/or incorrect info.
Mark
 

Thread Starter

paco

Joined Feb 20, 2008
2
Mark,
I finally got it working by creating a dll with the c++ functions and calling it dinamically from my Fortran program.
Thank you for your help,
Paco
 
Top