Calling C++ from FORTRAN

Paul Nord (PNORD@exodus.valpo.edu)
Thu, 01 Oct 1998 16:03:49 -0500 (CDT)


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?

C test.f
C
C Functions to demonstrate how to interact with the Root based
C Event Display.
C
C*****************************************************************************

program test

implicit none

CALL initdisplay()

CALL displayevent()

END

-------
/*****************************************
* FortranInterface.C
*
* Functions to interface Fortran and C routines for Event Display.
*
******************************************/

#include "TROOT.h"
#include "TRint.h"
#include "MDisplay.h"

extern void InitGui(); // initializer for GUI needed for interactive
interface
VoidFuncPtr_t initfuncs[] = { InitGui, 0 };

// Initialize the ROOT system
TROOT root("Rint","The ROOT Interactive Interface", initfuncs);
TRint *theApp;
MDisplay *display;

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);
}
--------------------------

And the makefile:

CXX = cxx
CXXFLAGS = -O -D__osf__ -D__alpha -I$(ROOTSYS)/include -V
LD = cxx
LDFLAGS = -g
SOFLAGS = -Wl,-expect_unresolved,* -call_shared
GLIBS = $(ROOTSYS)/lib/*.so -lX11 -lm -lPW -lXm -lXt

F77FLAGS = +ppu -K -V -cross_reference -names as_is

test.o : test.f
f77 -c $(F77FLAGS) test.f -o test.o

FortranInterface.o : FortranInterface.C

ftest : $(TEST_OBJS)
@echo "Creating Fortran frontend ..."
f77 -o ftest $(GLIBS) -lcxx -K $(TEST_OBJS) -cross_reference -V
@echo "done"

______________________

(Trust me that the rest of the TEST_OBJS compile just fine. And that the list
of files does include test.o and FortranInterface.o).

The error from the f77 of ftest is:

ld:
Unresolved:
initdisplay_
displayevent_
fort: Severe: Failed while trying to link.
make: *** [ftest] Error 1

???,
Paul Nord