Reputation: 19
The simple code file test2.cpp is
double tau;
// [[Rcpp::export]]
inline void set_tau(double t) {
tau = t;
}
// [[Rcpp::export]]
inline double get_tau() {
return tau;
}
It won't compile with Rcpp::sourceCpp("./src/test2.cpp") but the code compiles and runs after removing the inline keyword: code file test3.cpp is
double tau;
// [[Rcpp::export]]
void set_tau(double t) {
tau = t;
}
// [[Rcpp::export]]
double get_tau() {
return tau;
}
Rcpp::sourceCpp("./src/test2.cpp") throws an error
test2.cpp: In function ‘SEXPREC* sourceCpp_1_set_tau(SEXP)’:
test2.cpp:27:44: error: invalid use of void expression
27 | rcpp_result_gen = Rcpp::wrap(set_tau(t));
| ^
make: *** [/usr/lib/R/etc/Makeconf:177: test2.o] Error 1
Error in Rcpp::sourceCpp("./src/test2.cpp") :
Error 1 occurred building shared library.
>
But the code compiles fine from the command line g++ test2.cpp -g -c -o test2.o where g++ is version 9.4. In addition test3.cpp compiles and runs fine
> Rcpp::sourceCpp("./src/test3.cpp")
> set_tau(20)
> get_tau()
[1] 20
>
So it appears that Rcpp version 1.0.11 can't deal with an inline void function. Are their any work-arounds? Will g++ -o3 generate an inline function without an inline keyword, for example?
Upvotes: 0
Views: 39