I think I did. 
But if I don't, (1) my OS is Linux (Debian) kernel 2.6.8, R version 2.1.1.
(2) I generate the shared lib with a cutom makefile:

FC = g77
CC = gcc
RC = R CMD SHLIB
CFLAGS = -Df2cFortran -I/usr/local/lib/R/include -I/usr/local/include -g3 
-shared -fPIC
FFLAGS = -g3 -shared -fPIC

all: libtest

libtest: test.o prog.o
$(RC) test.o prog.o -o libtest.so

test.o: test.c test.h cfortran.h
$(CC) $(CFLAGS) -c test.c

prog.o: prog.f
$(FC) $(FFLAGS) -c prog.f

clean:
rm *.o *.so

(3) What I do in R is:
> dyn.load("libtest.so")
> .Call("simple_program")


Thanks,


Ricardo



On 04 Sep 2005 21:54:20 +0200, Peter Dalgaard <p.dalgaard@biostat.ku.dk> 
wrote:
> 
> Ricardo Luiz Andrade Abrantes <rabrantes82@gmail.com> writes:
> 
> > Hello there!
> > I almost don't deal with SEXPs. The function's name is main() it returns 
> a
> > SEXP wich is R_NilValue, thats all I use of SEXPs. This function call an
> > optimization packge and the output goes all to a text file.
> > Well, I followed Mr. Lumley's hint and used gdb with R and my program.
> > Together with a friend we could find the problem.
> > Inside the Fortran optimization package there's a subroutine called 
> cg(...),
> > and for some wierd reason this subroutine is never called (so, some
> > variables are not correctly initialized) and the program becomes crazy.
> > I did this small example to show you what happens:
> >
> > File: prog.f
> > -------------
> > subroutine cg()
> > write(*,*) 'Just a simple test'
> > end
> >
> > subroutine program()
> > write(*,*) 'Calling the function...'
> > call cg()
> > end
> >
> > File test.h
> > ------------
> > #include "cfortran.h"
> >
> > PROTOCCALLSFSUB0(PROGRAM,program)
> > #define program() CCALLSFSUB0(PROGRAM,program)
> >
> >
> > File test.c
> > ------------
> > #include <R.h>
> > #include <Rdefines.h>
> > #include <stdio.h>
> > #include "test.h"
> >
> >
> > SEXP simple_program(){
> > program();
> > return R_NilValue;
> > }
> >
> >
> > I compile the C and Fortran souces into a shared lib. I open R, do a
> > dyn.load("lib's name") and then a .Call("simple_program").
> > What I got?
> > Calling the function...
> > Segmentation fault
> >
> > What if I change the cg function's name to pp? My Fortran code is now:
> >
> > File: prog.f
> > -------------
> > subroutine pp()
> > write(*,*) 'Just a simple test'
> > end
> >
> > subroutine program()
> > write(*,*) 'Calling the function...'
> > call pp()
> > end
> >
> > And the output from R is:
> >
> > Calling the function...
> > Just a simple test
> > NULL
> >
> > Can anyone explain this? Is there a way to solve it? The optimization
> > package I use has the "cg" function, and I cannot change it's name!
> 
> Hmmmm.... Did you ever tell us
> 
> 1) Exactly what your platform is
> 2) How you generated the shared library (R CMD SHLIB, or?)
> 3) What you did to load it into R
> 
> ?
> 
> --
> O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
> c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
>

	[[alternative HTML version deleted]]

