<p><br>
On May 18, 2011 2:53 AM, &lt;<a href="mailto:soeren.vogel@uzh.ch">soeren.vogel@uzh.ch</a>&gt; wrote:<br>
&gt;<br>
&gt; Hello Dirk<br>
&gt;<br>
&gt; That was exactly the trick! Thanks a lot! Our class and code work so far, but it may take more time to debug or find bad design. Perhaps we will be back with more detailed questions. Anyway, one question already emerged. When librarying the class, assigning an object, do some calculations, whatever -- everything goes fine. Yet, when using R CMD BATCH on a file listing the same commands as by hand, R produces some nice information at the end, however, here it produces an segmentation fault, which does -- according to my small knowledge -- say something bad:<br>

&gt;<br>
&gt; &gt; proc.time()<br>
&gt;   user  system elapsed<br>
&gt;  0.702   0.017   0.714<br>
&gt; R(72992) malloc: *** error for object 0x2c9b604: incorrect checksum for freed object - object was probably modified after being freed.<br>
&gt; *** set a breakpoint in malloc_error_break to debug<br>
&gt;<br>
&gt;  *** caught segfault ***<br>
&gt; address 0x4909d58, cause &#39;memory not mapped&#39;<br>
&gt;<br>
&gt; Traceback:<br>
&gt;  1: save(list = ls(envir = .GlobalEnv, all.names = TRUE), file = outfile,     version = version, ascii = ascii, compress = compress, envir = .GlobalEnv,     precheck = FALSE)<br>
&gt;  2: save.image(name)<br>
&gt;  3: sys.save.image(&quot;.RData&quot;)<br>
&gt; aborting ...<br>
&gt;<br>
&gt; Any idea what goes wrong there?<br>
&gt;<br>
&gt; Regards<br>
&gt; Sören + Carlo<br>
&gt;<br>
 As you can see, the problem occurs when R is saving the worksheet.  At present an instance of a Rcpp module class cannot be saved. It is likely that this will need to be addressed by the person designing each C++ class that will be expressed in a module.  R can&#39;t serialize the contents of memory that it doesn&#39;t &quot;own&quot;.</p>

<p>The current fix is &quot;don&#39;t do that&quot;.  Add the --no-save or --vanilla in your call to R CMD BATCH to suppress saving the worksheet.</p>
<p>&gt; On 14.05.2011, at 18:17, Dirk Eddelbuettel wrote:<br>
&gt;<br>
&gt; Soeren,<br>
&gt;<br>
&gt; On 13 May 2011 at 20:07, <a href="mailto:soeren.vogel@uzh.ch">soeren.vogel@uzh.ch</a> wrote:<br>
&gt; | Compilation with R CMD CHECK FOO fails with the following error in 00install.out:<br>
&gt; |<br>
&gt; | Error in dyn.load(file, DLLpath = DLLpath, ...) :<br>
&gt; |   unable to load shared object &#39;/Users/sovo/GUTS/FOO.Rcheck/FOO/libs/i386/FOO.so&#39;:<br>
&gt; |   dlopen(/Users/sovo/GUTS/FOO.Rcheck/FOO/libs/i386/FOO.so, 6): Symbol not found: __ZN3FOOC1Ev<br>
&gt; |   Referenced from: /Users/sovo/GUTS/FOO.Rcheck/FOO/libs/i386/FOO.so<br>
&gt; |   Expected in: flat namespace<br>
&gt; |<br>
&gt; | The (original) class and its functions compile fine with R CMD SHLIB. So we guess that this error has something to do with the Rcpp modules implementation.<br>
&gt;<br>
&gt; It took me a few minutes with trial and error, but essentially the mistake<br>
&gt; seems to have been this:<br>
&gt;<br>
&gt; | &gt; |           FOO();<br>
&gt; | &gt; |           ~FOO();<br>
&gt;<br>
&gt; You declared the constructor and deconstructor but there was no code<br>
&gt; anywhere.  A pair of empty braces &#39; {}; &#39;  is all it takes.<br>
&gt;<br>
&gt; In the process, I renamed things from &#39;foo&#39; (just to be plain) to &#39;Baz&#39;.  So<br>
&gt; the file is now<br>
&gt;<br>
&gt; -----------------------------------------------------------------------------<br>
&gt; // baz_module.cpp<br>
&gt; #include &lt;Rcpp.h&gt;<br>
&gt;<br>
&gt; // from Baz.h<br>
&gt; class Baz<br>
&gt; {<br>
&gt; private:<br>
&gt;  double dtau;<br>
&gt;  std::vector&lt;double&gt; D, ee, ff, S;<br>
&gt;<br>
&gt; public:<br>
&gt;  int M;<br>
&gt;  std::vector&lt;double&gt; C, t, s, par;<br>
&gt;  std::vector&lt;int&gt; y;<br>
&gt;<br>
&gt;  Baz() {};<br>
&gt;  ~Baz() {};<br>
&gt;<br>
&gt;  double do_bar(std::vector&lt;double&gt; z);<br>
&gt; };<br>
&gt;<br>
&gt; // from Baz.cpp<br>
&gt; double Baz::do_bar(std::vector&lt;double&gt; z) {<br>
&gt;  // whatever it does<br>
&gt;  return 42.0;                   // need to return something here<br>
&gt; }<br>
&gt;<br>
&gt; RCPP_MODULE(baz){<br>
&gt;  using namespace Rcpp ;<br>
&gt;  class_&lt;Baz&gt;( &quot;Baz&quot; )<br>
&gt;   .constructor()<br>
&gt;   .field( &quot;M&quot; , &amp;Baz::M )<br>
&gt;   .field( &quot;C&quot; , &amp;Baz::C )<br>
&gt;   .method( &quot;do_bar&quot;, &amp;Baz::do_bar )<br>
&gt;   ;<br>
&gt; }<br>
&gt; -----------------------------------------------------------------------------<br>
&gt;<br>
&gt; and with the line<br>
&gt;<br>
&gt;   RcppModules: yada, baz<br>
&gt;<br>
&gt; we get this module loaded:<br>
&gt;<br>
&gt;<br>
&gt; R&gt; library(mypackage)<br>
&gt; R&gt; Baz<br>
&gt; C++ class &#39;Baz&#39; &lt;0x1c37db0&gt;<br>
&gt; Constructors:<br>
&gt;   Baz()<br>
&gt;<br>
&gt; Fields:<br>
&gt;   std::vector&lt;double, std::allocator&lt;double&gt; &gt; C<br>
&gt;   int M<br>
&gt;<br>
&gt; Methods:<br>
&gt;    double do_bar(std::vector&lt;double, std::allocator&lt;double&gt; &gt;)<br>
&gt;<br>
&gt; R&gt;<br>
&gt; R&gt; bb &lt;- new(Baz)<br>
&gt; R&gt; bb<br>
&gt; C++ object &lt;0x18c8f90&gt; of class &#39;Baz&#39; &lt;0x1c37db0&gt;<br>
&gt; R&gt; bb$M &lt;- 12<br>
&gt; R&gt; print(bb$M)<br>
&gt; [1] 12<br>
&gt; R&gt; print(bb$C)<br>
&gt; numeric(0)<br>
&gt; R&gt; bb$C &lt;- seq(1.1, 5.5, by=1.1)<br>
&gt; R&gt; bb$C<br>
&gt; [1] 1.1 2.2 3.3 4.4 5.5<br>
&gt; R&gt; R&gt; print(bb$do_bar(1:4))<br>
&gt; [1] 42<br>
&gt; R&gt;<br>
&gt;<br>
&gt;<br>
&gt; I hope you can take it from here.<br>
&gt;<br>
&gt; Cheers, Dirk<br>
&gt;<br>
&gt; --<br>
&gt; Gauss once played himself in a zero-sum game and won $50.<br>
&gt;                     -- #11 at <a href="http://www.gaussfacts.com">http://www.gaussfacts.com</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Rcpp-devel mailing list<br>
&gt; <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
&gt; <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</p>