- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everybody,
I want to call a c++-function in a fortran program, using Compaq Visual Fortran as a Fortran compiler and Microsoft Visual C++ as a c++ compiler. I have written the following pieces of code:
the fortran main program:
program frotc
implicit none
integer :: x,y,max
write(*,*) "Bitte geben Sie zwei Zahlen ein: "
read(*,*) x,y
call sum(x,y,max)
write(*,*)"Das Maximum ist: ",max
end program frotc
and the to-be-called c++ function:
extern "C"
{void_stdcall max(int*,int*,int*);
}
void max(int*x,int*y,int*max){if(*x<=*y) *max=*y;
else *max=*x;
}
but I have no clue how to link these two programs together. Id be grateful for every piece of advice!
Thanks,
Isomorphismus
I want to call a c++-function in a fortran program, using Compaq Visual Fortran as a Fortran compiler and Microsoft Visual C++ as a c++ compiler. I have written the following pieces of code:
the fortran main program:
program frotc
implicit none
integer :: x,y,max
write(*,*) "Bitte geben Sie zwei Zahlen ein: "
read(*,*) x,y
call sum(x,y,max)
write(*,*)"Das Maximum ist: ",max
end program frotc
and the to-be-called c++ function:
extern "C"
{void_stdcall max(int*,int*,int*);
}
void max(int*x,int*y,int*max){if(*x<=*y) *max=*y;
else *max=*x;
}
but I have no clue how to link these two programs together. Id be grateful for every piece of advice!
Thanks,
Isomorphismus
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you're linking the two together, the process is pretty straighforward (this example is for VS.NET2003 with IVF):
- Create a new, empty solution in VS
- Create a new C++ Library project
- Change your function paramsto use refs instead of pointers.
- Create a new Fortran project and make these property changes in ALL configs:
- Change Fortran|External Procedures: "C, REFERENCE"
- Add Linker|General|Additional Library Directory: "..{C_PROJECT}$(OutDir)" (replacing {C_PROJECT} with the dir from #2, usually the same as the project name)
- Add Linker|Input|Additional Dependencies: "{C_PROJECT}.lib" (replacing {C_PROJECT} with theoutput namefrom #2, usually the same as the project name)
- Add Debugging|Working Directory: "$(TargetPath).."
- Set Project|Project Dependencies so the Fortran project is dependent on the C project.
- Set Project|Set Startup Project to be the Fortran project.
I've attached a solution .ZIP with your code. Since I didn't include my user option files, you'll probably need to do step 3.4, but I think the rest will be done already.
BTW, If you want to do the C++ as a DLL, it's just a little more complicated, and it's easier to move all your projects into the root.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page