Calling Fortran DLL from C++ using Visual Studio 2008 RRS feed

  • Question

  • I am trying to do something fairly simple.  I have a fortran program that I compiled as a DLL and would like to call the fortran functions from a C++ program.   But I am having some problems: Here is a brief example of what I am doing:
    1) created a new intel fortran project, a blank DLL
    2) wrote a simple Fortran program:  (fortfunc.F90)
        subroutine FR1(N,M)
      integer function

    3) I compiled it using visual studio 2008 and it created the appropriate DLL  (fortfunc.dll)

    4) I created another new project, C++ window32 console blank project
    5) wrote a simple C++ program to call the fortran functions
        #include <iostream>
       using namespace std;
       extern "C" {
       void __stdcall FR1(int *a, int *b);
        int __stdcall FF1(int *c);
    int main() {
       int n = 10,nSq,nCube;
       cout <<
    "The square is:" << nSq << endl;
       cout <<
    "The cube is:" << nCube << endl; 
       return 0;

    5) I moved the fortfunc.dll to the same folder where my main.cpp exists
    6) from the property->Linker->inputs->Additional Dependencies    I added the fortfunc.dll
    note: I also tried adding the whole directory path and got the same results

    7) now I tried to compile the C++ and here is the error:  
    1>fortfunc.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2F8
    1>Build log was saved at "file://c:\projects\sandbox\test2\test2\Release\BuildLog.htm"
    1>test2 - 1 error(s), 0 warning(s)

    My question is pretty simple, what is the correct to add the dll so the C++ can call the fortran functions?

    Thank you
    Tuesday, March 2, 2010 2:58 PM