[Rcpp-devel] Segmentation faults

Balamuta, James Joseph balamut2 at illinois.edu
Fri Dec 6 23:00:46 CET 2019

Greetings and Salutations Brook, 

The segfault is related to `int main() {}`. There is no need to use `int main() {}` unless you want to make this standalone in which case you want to use RInside to embed R within a C++ application.

Rcpp enables embedding C++ within R. So, R already is using its own `int main() {}`. Modifying code to the following should work:

In C++


    #include <Rcpp.h>

    // [[Rcpp::plugins(cpp11)]]
    // [[Rcpp::export]]
    void test_fun()
      auto i = Rcpp::IntegerVector::create(1,2);
      Rcpp::Rcout << "Hello World!" << std::endl;

In R

# Hello World! 

For other examples, consider looking at examples from the introduction paper: 



´╗┐On 12/6/19, 3:48 PM, "Rcpp-devel on behalf of Brook Milligan" <rcpp-devel-bounces at lists.r-forge.r-project.org on behalf of brook at nmsu.edu> wrote:

    I am trying to build some simple test cases of Rcpp.  One of the simplest I can think of is below.
    #include <Rcpp.h>
    int main ()
      auto i = Rcpp::IntegerVector::create(1,2);
    This compiles fine and links against libR, but segmentation faults when run.  My test system is a Mac with clang++.
    Is there an obvious reason this should not work?
    Rcpp-devel mailing list
    Rcpp-devel at lists.r-forge.r-project.org

More information about the Rcpp-devel mailing list