SUBROUTINE COLNEW (NCOMP, M, ALEFT, ARIGHT, ZETA, IPAR, LTOL,
1 TOL, FIXPNT, ISPACE, FSPACE, IFLAG,
2 FSUB, DFSUB, GSUB, DGSUB, GUESS)
IMPLICIT REAL*8 (A-H,O-Z)
DIMENSION M(1), ZETA(1), IPAR(1), LTOL(1), TOL(1), DUMMY(1),
1 FIXPNT(1), ISPACE(1), FSPACE(1)
in a Fortran .f file would be given the following c++ declaration.
extern "C" void colsys_(const int *ncomp,
const int *m,
const double *aleft,
const double *aright,
const double zeta[],
int ipar[],
int ltol[],
double tol[],
double fixpnt[],
int ispace[],
double fspace[],
int *iflag,
void (*fsub)(double *x,
double *z,
double *f),
void (*dfsub)(double *x,
double *z,
double *df), // 2d array
void (*gsub)(int *i,
double *z,
double *g),
void (*dgsub)(int *i,
double *z,
double *dg),
void (*guess)(double *x,
double *z,
double *dmval));
Notice that the function is declared with external linkage by the
extern keyword. Also there is an underscore at the end of the
lowercase name. Finally you must figure out what the arguments types
are. Be careful with arrays! I will not try to explain how arrays in
Fortran differ from those in c++: look on the web.
The second problem comes from linking. When you call the linker from a compiler, the compiler tells the linker what libraries you need to link. When you try to link the Fortran code with your C++ code, the linker will not look for the required Fortran libraries. What you must do is specify these libraries using options like -L for the library path and -l to specify which libraries to link. Often the problem is trying to find out which library you need for a particular symbol. One way to do this is to compile a small fortran program like the following ``Hello World'' program and specify the compiler option to be verbose (-v for g77). This will tell you which libraries the Fortran compiler is telling the linker (usually ld) to link and thus, you can find the libraries you need.
Here is the ``Hello World'' program in Fortan 77 which I will assume is in a file called hello.f:
c
c Hello, world.
c
Program Hello
implicit none
logical DONE
DO while (.NOT. DONE)
write(*,10)
END DO
10 format('Hello, world.')
END
Compile this with the command g77 -v hello.f or using the appropriate compiler on your system. This gives me (on a linux box) the following output (I have separated the actual lines for clarity. The compiler will spit out everything bunched up.):
g77 version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (from FSF-g77 version 0.5.24-19981002) Driving: g77 -v hello.f -lg2c -lm Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/f771 hello.f -quiet -dumpbase hello.f -version -fversion -o /tmp/ccSrpdYq.s GNU F77 version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release). GNU Fortran Front End version 0.5.24-19981002 as -V -Qy -o /tmp/ccW4J4DI.o /tmp/ccSrpdYq.s GNU assembler version 2.9.5 (i386-redhat-linux) using BFD version 2.9.5.0.22 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66 -L/usr/i386-redhat-linux/lib /tmp/ccW4J4DI.o -lg2c -lm -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/crtend.o /usr/lib/crtn.oThe last bunch of code is what we want. Thus, I see that I should include the following directories in my linking path by using the -L option:
-L/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66 -L/usr/i386-redhat-linux/libI also will need to link with the following -l options:
-lg2c -lm -lgcc -lc -lgccI may need to include the following object files
/usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/crtend.o /usr/lib/crtn.o /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/crtbegin.oThe file /tmp/ccW4J4DI.o is the actual source file (since I am compiling directly: there is no hello.o produced) so we do not need it. Finally there are the options
-m elf_i386 -dynamic-linker /lib/ld-linux.so.2I do not know enough about Fortran yet to know if you need all this, but if should give you something to start playing with to get the linker working. Good luck.