Before writing the client, let's generate a Fortran implementation as well. It is highly instructive to see how the makefiles differ between the different language bindings. From within the minimal/libCxx directory we do.
% cd ../libF90
% babel -sF90 ../../hello.sidl
This time there's even more files generated (Fortran 90 bindings are harder after all), and we need to add our implementation to the Hello_World_Impl.F90 file. The modified code will look like this.
1 ! 2 ! Method: getMsg[] 3 ! 4 5 recursive subroutine Hello_World_getMsg_mi(self, retval, exception) 6 use sidl 7 use sidl_BaseInterface 8 use sidl_RuntimeException 9 use Hello_World 10 use Hello_World_impl 11 ! DO-NOT-DELETE splicer.begin(Hello.World.getMsg.use) 12 ! Insert-Code-Here {Hello.World.getMsg.use} (use statements) 13 ! DO-NOT-DELETE splicer.end(Hello.World.getMsg.use) 14 implicit none 15 type(Hello_World_t) :: self ! in 16 character (len=*) :: retval ! out 17 type(sidl_BaseInterface_t) :: exception ! out 18 19 ! DO-NOT-DELETE splicer.begin(Hello.World.getMsg) 20 retval='Hello from Fortran 90!' 21 ! DO-NOT-DELETE splicer.end(Hello.World.getMsg) 22 end subroutine Hello_World_getMsg_mi 23
Note that the C function appears as a subroutine in Fortran. What was the return value appears here as the argument retval (line 5). For Fortran 90 there are also two splicer blocks per subroutine, one for use statements (lines 11-13) and another for the actual implementation (lines 19-21). This is where we put our implementation by setting retval to the string we want.
There are important differences in this Makefile from the C++ implementation, so we reproduce it in its entirety here.
1 # A minimal makefile for Fortran 90 Babel Impl 2 # Assumes babel-config is in the current path 3 # Assumes babel -sF90 ../../hello.sidl is already run 4 5 include babel.make 6 7 OBJS = $(IORSRCS:.c=.o) $(TYPEMODULESRCS:.F90=.o) \ 8 $(SKELSRCS:.c=.o) $(STUBMODULESRCS:.F90=.o) $(STUBSRCS:.c=.o) \ 9 $(IMPLMODULESRCS:.F90=.o) $(IMPLSRCS:.F90=.o) 10 11 all: libhello.a 12 13 .SUFFIXES: 14 .SUFFIXES: .F90 .c .o 15 .F90.o: 16 gcc -E -traditional -P -o $*.tmp -x c \ 17 `babel-config --includes-f90` $< 18 sed -e 's/^#pragma.*$$//' < $*.tmp > $*.f90 19 gfortran -c -o $@ `babel-config --includes-f90-mod` $*.f90 20 rm -f $*.f90 $*.tmp 21 22 .c.o: 23 gcc `babel-config --includes` `babel-config --includes-f90` -c $< 24 25 libhello.a: $(OBJS) 26 ar cru $@ $(OBJS) 27 ranlib $@ 28 29 .PHONY: clean new 30 31 clean: 32 $(RM) *.o *.mod *~ babel.make.depends babel.make.package 33 34 new: clean 35 $(RM) $(IORHDRS) $(IORSRCS) $(TYPEMODULESRCS) $(SKELSRCS) \ 36 $(STUBMODULESRCS) $(STUBSRCS) $(STUBHDRS) libhello.a
Again, we simply type make, and should end up with another libhello.a file.