Last active
August 29, 2015 14:21
-
-
Save molpopgen/989ec678664d083bf4a3 to your computer and use it in GitHub Desktop.
Issue with Rcpp -- gcc vs clang++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(Rcpp) | |
Sys.setenv("PKG_CXXFLAGS" = "-std=c++11") | |
sourceCpp("tuple.cc",verbose=TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(Rcpp) | |
Sys.setenv("PKG_CXXFLAGS" = "-std=c++11 -DUSE_DELETER") | |
sourceCpp("tuple.cc",verbose=TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Rcpp.h> | |
#include <tuple> | |
/* | |
Linking fails on GCC unless I use the block below that puts an overload of standard_delete_finalizer in ns Rcpp. | |
(I can also provide my own custom deleter, a la std::unique_ptr, which works fine.) | |
All is good with clang++ however | |
The type of error message I get with g++ 4.92 is: | |
Error in dyn.load("/tmp/RtmpmRO8Pk/sourcecpp_43e839c52664/sourceCpp_49632.so") : | |
unable to load shared object '/tmp/RtmpmRO8Pk/sourcecpp_43e839c52664/sourceCpp_49632.so': | |
/tmp/RtmpmRO8Pk/sourcecpp_43e839c52664/sourceCpp_49632.so: undefined symbol: _ZN4Rcpp25standard_delete_finalizerISt5tupleIIiiEEEEvPT_ | |
*/ | |
#ifdef USE_DELETER | |
namespace Rcpp { | |
template<> | |
inline void standard_delete_finalizer<std::tuple<int,int> >( std::tuple<int,int> * t ) { delete t; } | |
} | |
#endif | |
//Pretend that this is a namespace in another header-only Rcpp-based library | |
namespace foo { | |
/* | |
This appears to be the culprit. | |
If I do not use this typedef, all is good with GCC. | |
However, I want this type so that I can: | |
1. refer to it when SEXPs are passed to other functions. | |
2. Change what the type is and not have to find all the places | |
where it is referred to and change them, too. | |
*/ | |
using tuple_t = std::tuple<int,int>; | |
/* | |
Note: if foofunc is NOT a template, | |
everything "just works" as expected, | |
but we're trying to get a set of templates | |
gluing an existing header-only C++11 library | |
and Rcpp, in order to provide access to the former | |
in R. | |
*/ | |
template<typename T> | |
SEXP foofunc() | |
{ | |
return Rcpp::XPtr<tuple_t>(new tuple_t(T(),T())); | |
} | |
} | |
//' Pretend that this is some function using our new "glue" library with a concrete type | |
// [[Rcpp::export()]] | |
SEXP foofunc_caller() { return foo::foofunc<int>(); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment