g++ errors when trying to compile c++11 with Rcpp

后端 未结 3 1826
生来不讨喜
生来不讨喜 2021-02-08 15:07

SYSTEM SPEC:

  • OS - Mac OS X 10.6.8 (Snow Leopard)
  • g++ - Macports gcc 4.8.1_2+universal
3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-08 15:48

    Quick ones:

    • you are behind on Rcpp which is at a released version 0.10.4

    • the version you are using (0.10.3) does have have a plugin for C++11

    • there is an entire article at the Rcpp Gallery which details this.

    So allow me to quote from that C++11 piece on the Rcpp Gallery:

    R> library(Rcpp)
    R> sourceCpp("/tmp/cpp11.cpp")
    R> useAuto()
    [1] 42
    R> 
    

    where the code in /tmp/cpp11.cpp is as follows:

    #include 
    
    // Enable C++11 via this plugin (Rcpp 0.10.3 or later)
    // [[Rcpp::plugins("cpp11")]]
    
    // [[Rcpp::export]]
    int useAuto() {
        auto val = 42;      // val will be of type int
        return val;
    }
    

    If that does not work for you, then your system is not set up right. In other words, this is not a question for the Rcpp tag -- but rather for 'how do I set up my path to invoke the version of g++ I think I should be invoking'.

提交回复
热议问题