Re: Calling C++ from FORTRAN
Pasha Murat (murat@cdfsga.fnal.gov)
Thu, 1 Oct 1998 17:52:21 -0500 (CDT)
Paul Nord writes:
> Good Day,
>
> I'd like to be able to drive the root system from a FORTRAN program.
>
> I thought that this should work. Can anyone tell me what's wrong?
>
> program test
>
> implicit none
>
>
> CALL initdisplay()
>
> CALL displayevent()
>
> END
>
>
> int initdisplay_() {
> // Create interactive interface
> theApp = new TRint("ROOT example", NULL, 0, NULL, 0);
> display = new MDisplay("display");
> return(0);
>
> }
>
>
> int displayevent_() {
> theApp->Run(kTRUE);
> return(0);
> }
>
> The error from the f77 of ftest is:
>
> ld:
> Unresolved:
> initdisplay_
> displayevent_
> fort: Severe: Failed while trying to link.
> make: *** [ftest] Error 1
--------------------------------------------------------------------------------
As C++ compilers by default mangle the routine names and FORTRAN
doesn't expect it, you need to describe your FORTRAN-callable routines as
extern "C" to get their names not mangled, for example:
extern "C" int initdisplay_() {
.....
}
regards, pasha