RE: [Dev-C++] Mixed Language Programming w/Dev-Cpp
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Scott W. <se...@al...> - 2002-10-30 20:14:07
|
Thanks to everyone who responded to my question about mixed language programming (particularly to Horst for the references). Persistence has paid off! For the record . . Turns out Dev-Cpp works quite nicely with mixing Fortran and C. At compile, gcc implicitly invokes g77 for any Fortran source files and the resulting object files are linked without a problem; So including Fortran source files in a Dev-Cpp project appears to be seamless. Actually using the Fortran subroutines takes a little more work. First, the Mingw libraries libg2c and libm must be linked, i.e., Project Options : Linker Options : -lg2c -lm (in that order!). Next, the Mingw header file g2c.h must be included in any C source file that will call C. libg2c and g2c.h are gcc's versions of f2c. However, as near as I can tell, this isn't an f2c operation (translating Fortran to C then compiling from C source), rather, the Fortran source files are compiled with g77 and so retain the native efficiencies of their Fortran implementation; the library and header files merely provide the interface for C. Prototyping the Fortran subroutines is a little tricky but I found a use for f2c after all! When used with the -P switch, it produces a file with subroutine prototypes to be used in C. After that, it took some trial & error to figure out how to correctly declare & pass the variables from C. Biggest problem I had was with the C function passed to and called from the Fortran routines (using their own internally declared variables). Essentially I had to create a shell of the C routine to be called by the Fortran routines where I adjusted array indexing and then call the real C routine. Hope that is helpful anyone else interested in the issue. Thanks again for the feedback. Scott |