Re: Calling C++ from FORTRAN

From: Jarek Grebieszkow (Jarek.Grebieszkow@cern.ch)
Date: Thu Oct 01 1998 - 23:58:37 MEST


You should add in your c++ source file declaration of initdisplay_
and displayevent_:

extern "C"  {
 int initdisplay_();
 int displayevent_();
}

extern "C" means that their names "C" linking convention otherwise
c++ compilator generates names according to the c++ naming convention.

						Jarek

On Thu, 1 Oct 1998, Paul Nord wrote:


> *
> ******************************************/
> 
> #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
> 



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