Skip to content

R crash with dyn.load

2 messages · Thibault Helleputte, Martyn Plummer

#
Hello,

I try to incorporate C code in R.

suppose I have the following C code:

#include <R.h>
#include <stdio.h>

int main(int *n)
{
    int i;
    for(i=0; i < *n; i++) {
        printf("Hello, world!\n");
    }
 }


in a file named "hello.c". First I make:

g++ -c hello.c -o hello.o -I
"/Library/Frameworks/R.framework/Versions/2.8/Headers/"
g++ -dynamic hello.o -o hello.so

I work on mac, and that's why I have to set the -dynamic option. First
of all, I don't understand why I have to specify the path to R.h, but if
I don't, R.h isn't found.

My problem is the following: once the .so is generated, without any
warning or error, I open my R envirronment and type
then push on enter, and then R runs  hours, without giving me the
command invite again. What am I doing wrong?

Thank you.
#
On Thu, 2008-12-18 at 17:18 +0100, Thibault Helleputte wrote:
It might have something to do with the fact that you call your function
"main". Try renaming it.

Also have a look at section 5.5 of the "Writing R Extensions" manual on
creating shared objects for loading into R.

Martyn
-----------------------------------------------------------------------
This message and its attachments are strictly confidenti...{{dropped:8}}