[R] R crash with dyn.load
Martyn Plummer
plummer at iarc.fr
Thu Dec 18 17:32:34 CET 2008
On Thu, 2008-12-18 at 17:18 +0100, Thibault Helleputte wrote:
> 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
>
> > dyn.load("/path/to/my/hello.so")
>
> then push on enter, and then R runs hours, without giving me the
> command invite again. What am I doing wrong?
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
> Thank you.
-----------------------------------------------------------------------
This message and its attachments are strictly confidenti...{{dropped:8}}
More information about the R-help
mailing list