Re: Calling C++ from FORTRAN

From: Pasha Murat (murat@cdfsga.fnal.gov)
Date: Fri Oct 02 1998 - 00:52:21 MEST


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



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:38 MET