Re: [Rd] Memory problems with a custom R package

From: Hin-Tak Leung <hin-tak.leung_at_cimr.cam.ac.uk>
Date: Tue 12 Sep 2006 - 12:23:33 GMT

compiler/platform?

I did this:
R CMD SHLIB helloworld.cpp

Then this in R:
 > dyn.load("helloworld.so")
 > .Call("helloworld")

and it doesn't segfault. (x86_64 linux with 32-bit R).

Tom McCallum wrote:
> Hi everyone,
>
> I have been attempting to build a very simple R package interfacing with
> some very simple C++ code. Everything I try though results in the
> function working but on return it produces a memory error. Here is the
> output:
>
> ***********OUTPUT***************************
>

>> library(MyPackage)
>> hello();

>
> *** caught segfault ***
> address 0x3, cause 'memory not mapped'
>
> **********END OUTPUT*************************
>
> I have read that some time this occurs because it cannot find the function
> in the shared library but I have tested this theory with a simple text
> message and this is displayed but again the memory error occurs.
>
> The C++ code has been reduced to the simplest possible:
>
> *** helloworld.h
>
> extern "C" void helloworld(void);
>
> *** helloworld.cpp
>
> #include <iostream>
> #include "helloworld.h"
>
> void helloworld(void) {
> // This was my test line that was displayed as described above.
> // std::cout << "My first R Package Test." << std::endl;
> }
>
> I also wrote an R wrapper called hello as follows:
>
> *** helloworld.R
>
> hello <- function()
> {
> .Call("helloworld", PACKAGE="MyPackage");
> }
>
> The namespaces file (NAMESPACE) is as follows:
>
> useDynLib(MyPackage)
> export(hello)
>
> I have compared mine against other package sources available that do the
> same thing and cannot find the key difference.
>
> Thank you for your help in advance,
>
> Tom
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Sep 12 22:30:06 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 12 Sep 2006 - 13:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.