Skip to content

GetRNGstate() crashes with 'Segmentation fault'

4 messages · Brian Ripley, Timur Elzhov

#
Dear R-masters,


I tried to compile this simpel C-code:

//-----------------

#include<R.h>

int main()
{
    GetRNGstate();
    return 0;
}
 
//-----------------

Compiling:

~> gcc -o a  a.c -I/usr/lib/R/include/ -L/usr/lib/R/bin/ -lR
~> ldd a
        libR.so => /usr/lib/libR.so (0x40018000)
        libc.so.6 => /lib/libc.so.6 (0x401a8000)
        libblas.so.2 => /usr/lib/libblas.so.2 (0x402bb000)
        libreadline.so.4 => /lib/libreadline.so.4 (0x4031e000)
        libdl.so.2 => /lib/libdl.so.2 (0x40347000)
        libncurses.so.5 => /lib/libncurses.so.5 (0x4034a000)
        libm.so.6 => /lib/libm.so.6 (0x40389000)
        libz.so.1 => /usr/lib/libz.so.1 (0x403ab000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

~> ./a
Segmentation fault


Where am I wrong?
I'm using R 1.6.1, glibc-2.3.1 on Debian woody system.

Thanks a lot!

--
WBR,
Timur.
#
Whyever do you think that should work?

If you want to link against libR.so and call into R, you do need to
initialize R, and you have not done so.

I also don't see that the program has any use.  The complicated ways to
manipulate the random number generator are really only of any use from R
code (via C code, perhaps).
On Fri, 20 Dec 2002, Timur Elzhov wrote:

            

  
    
#
On Fri, Dec 20, 2002 at 04:56:31PM +0000, ripley at stats.ox.ac.uk wrote:

            
Yes, this code was intended to be used from R!  I decided just to
test it this way ;) .  So, it seems to be impossible to write
separate program, link it against R library, test it (and then create
shared library to used from within R)?

Thanks.


WBR,
Timur.
#
On Fri, 20 Dec 2002, Timur Elzhov wrote:

            
It's not impossible, but it is not straightforward.