Hi all,<br><br>I'm completely new to R and Rcpp, and I thought I'd just make a simple program to see how Rcpp works. Here is the code:<br><br><code><br>#include <Rcpp.h><br>#include <cstdio><br>#include <cstdlib><br>
#include <iostream><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 << "--------" << num_of_numbers << "--------------\n";<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 < argc; ++i)<br> {<br>
numbers[i-1] = atof(argv[i]);<br> std::cerr << numbers[i-1] << "\n";<br> }<br> get_weights(num_of_numbers, numbers);<br> return 0;<br>}<br></code><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><code><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></code><br><br>I'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>