Hi all,<br><br>I&#39;m completely new to R and Rcpp, and I thought I&#39;d just make a simple program to see how Rcpp works. Here is the code:<br><br>&lt;code&gt;<br>#include &lt;Rcpp.h&gt;<br>#include &lt;cstdio&gt;<br>#include &lt;cstdlib&gt;<br>
#include &lt;iostream&gt;<br>RcppExport void get_weights(int num_of_numbers, double* numbers);<br>RcppExport void get_weights(int num_of_numbers, double* numbers)<br>{<br>    std::cerr &lt;&lt; &quot;--------&quot; &lt;&lt; num_of_numbers &lt;&lt; &quot;--------------\n&quot;;<br>
    Rcpp::NumericVector vec(1);<br>}<br>int main(int argc, char* argv[])<br>{<br>    int num_of_numbers = argc - 1;<br>    double* numbers = new double[num_of_numbers];<br>    for(int i = 1; i &lt; argc; ++i)<br>    {<br>
        numbers[i-1] = atof(argv[i]);<br>        std::cerr &lt;&lt; numbers[i-1] &lt;&lt; &quot;\n&quot;;<br>    }<br>    get_weights(num_of_numbers, numbers);<br>    return 0;<br>}<br>&lt;/code&gt;<br><br>I can compile and link this code without any problems. However, when I run it, I get a segfault in<br>
get_weights. I traced the segfault using gdb, and the problem sees to come from this:<br><br>&lt;code&gt;<br>(gdb) run  1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7<br>Starting program: /home/patricky/tmp/stl 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7<br>
[Thread debugging using libthread_db enabled]<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>--------21--------------<br><br>Program received signal SIGSEGV, Segmentation fault.<br>
0x00007ffff6c3ed70 in ?? () from /usr/lib64/R/lib/libR.so<br>(gdb) up<br>#1  0x00007ffff6c4049b in Rf_allocVector () from /usr/lib64/R/lib/libR.so<br>(gdb) <br>#2  0x0000000000401814 in Vector (this=0x7fffffffdf80, size=@0x7fffffffdf9c) at /usr/share/lib/R/x86_64-pc-linux-gnu-library/2.12/Rcpp/include/Rcpp/vector/Vector.h:130<br>
130             RObject::setSEXP( Rf_allocVector( RTYPE, size) ) ;<br>&lt;/code&gt;<br><br>I&#39;ve rather stumped at this problem, and would appreciate any help that you guys can provide.<br><br>Thanks a lot.<br><br>Patrick<br>