[Rd] .Call with C and Fortran together (PR#8122)

Thomas Lumley tlumley at u.washington.edu
Mon Sep 5 19:05:24 CEST 2005


>
> In some machines I don't get the segmentation fault problem, but I don't get the
> message "Just a simple test" either (when using "cg" as the subroutine's name).
> I believe this is bug in R because if I change my C interface again to return a
> 0 instead of a R_NilValue, and then use it with another C program wich loads the
> dynamic library amd call the function simple_program(), everything work
> perfectly.
>

I don't think it is an R bug.  I think it is because there is already a 
Fortran function called cg in R. The fact that changing the name matters 
suggest that you have a linking problem, and this turns out to be the 
case.

When I try running your code under gdb in R as Peter Dalgaard suggested 
(after editing it to use R's macros for calling fortran from C instead of 
"cfortran.h" which I don't have), I get

> .Call("simple_program")
  Calling the function...

Program received signal SIGSEGV, Segmentation fault.
0x081604e5 in cg_ (nm=0x9e5dda4, n=0xbfefccfc, ar=0xbfefcce8, ai=0x89a826,
     wr=0x9e5dda4, wi=0x9790cc0, matz=0x56090a0, zr=0x80992d4, zi=0x0, 
fv1=0x0,
     fv2=0x9e745f8, fv3=0x89a810, ierr=0x706d6973) at eigen.f:3416
3416          IERR = 10 * N
Current language:  auto; currently fortran


That is, your program is calling the Fortran subroutine CG in eigen.f, 
rather than your CG.

There should be some set of linker flags that makes sure your definition 
of CG is used, but I don't know what it would be (and it's probably very 
platform dependent)

 	-thomas



More information about the R-devel mailing list