On Thu, 17 Jan 2002, H.S.Rai wrote:

> to call fortran_compiled_subroutine() [ available as
> object file "fcf.o" ] in a C++ program ( prog.cc ). I tried

> g++ -c prog.cc
>
> g++ -o prog prog.o fcf.o

you have to take care of some other detail.

1) Name mangling :

Since C++ allows function overloading the functiona names are mangled, i.e.
when you call foo() from within c++, the function that will get actually called
will be a mangled version say Ih_foo(). If the library was itself produced by
the same compiler ( or atleast having the same mangling std ) it will link
with the correct one.

But since you have a fortran library, you have to stop this name mangling.
You have to declare your function in an extern "C" block i.e.

extern "C" void foobar();

2) do an nm on the fortran library to get the correct exported function
name, cause some compilers pre/append some underscores to the function.
Take care about capitalisation too, the function you call has to match
exactly with the function exported by your fortran library.


3) Fortran stores 2d array in column major format, you have to take care
of that, 1d arrays are no problem.

4) Fortran does not have null terminated strings, so it actually passes a
hidden int along with all the other arguments, so you have to pass in the
strlength.

-- sreangsu


_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to