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++
test_fun.cpp
#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
Rcpp::sourceCpp("path/to/test_fun.cpp")
test_fun()
# Hello World!
For other examples, consider looking at examples from the introduction paper:
https://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-introduction.pdf
Sincerely,
JJB
On 12/6/19, 3:48 PM, "Rcpp-devel on behalf of Brook Milligan"
<[email protected] on behalf of [email protected]>
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?
Cheers,
Brook
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel