[Rd] Memory problems with a custom R package

Hin-Tak Leung hin-tak.leung at cimr.cam.ac.uk
Tue Sep 12 14:23:33 CEST 2006


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 at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel




More information about the R-devel mailing list