From tom.mccallum at levelelimited.com  Tue Sep 12 12:39:41 2006
From: tom.mccallum at levelelimited.com (Tom McCallum)
Date: Tue, 12 Sep 2006 11:39:41 +0100
Subject: [Rd] Memory problems with a custom R package
Message-ID: <op.tfrg8fgpffxks9@norisk>

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




[Rd] Memory problems with a custom R package
Tom McCallum