我正在使用 RcppEigen 和 Eigen 不受支持的模块来处理张量操作。我使用函数 sourceCpp 来编译我的代码,但它失败了一些我无法理解的错误声明。我在 Rstudio 之外使用 Clion 测试了相同的代码,但是,它成功通过了。我的操作系统是Windows10,R版本是3.6.3,RcppEigen版本是0.3.3.9.1。代码和错误声明如下所示。
sourceCpp(code='
#include <./unsupported/Eigen/CXX11/Tensor>
#ifdef Realloc
#undef Realloc
#endif
#include <Rcpp.h>
#include <RcppCommon.h>
#include <RcppEigen.h>
#include <iostream>
// [[Rcpp::depends(RcppEigen)]]
using namespace std;
using namespace Eigen;
// [[Rcpp::export]]
Tensor<double, 2> tensorContractTest(int n)
{
Tensor<double, 3> a(n, n, n); a.setConstant(1.);
Tensor<double, 1> b(n); b.setConstant(1.);
auto indexPair = Eigen::array<IndexPair<int>, 1>{IndexPair<int>(2,0)};
Tensor<double, 2> result = a.contract(b, indexPair);
return result;
}
')
错误声明:
C:/RBuildTools/3.5/mingw_64/bin/g++ -std=gnu++11 -I"F:/R-3.6.3/include" -DNDEBUG -I"F:/R-3.6.3/library/Rcpp/include" -I"F:/R-3.6.3/library/RcppEigen/include" -I"C:/Users/dell/AppData/Local/Temp/RtmpoXhaKM/sourceCpp-x86_64-w64-mingw32-1.0.6" -O2 -Wall -mtune=core2 -c file430864722709.cpp -o file430864722709.o
In file included from F:/R-3.6.3/include/R.h:91:0,
from F:/R-3.6.3/library/Rcpp/include/Rcpp/r/headers.h:71,
from F:/R-3.6.3/library/Rcpp/include/RcppCommon.h:29,
from F:/R-3.6.3/library/Rcpp/include/Rcpp.h:27,
from file430864722709.cpp:6:
F:/R-3.6.3/include/R_ext/RS.h:55:0: warning: "ERROR" redefined
#define ERROR ),error(R_problem_buf);}
^
In file included from C:/RBuildTools/3.5/mingw_64/x86_64-w64-mingw32/include/windows.h:71:0,
from F:/R-3.6.3/library/RcppEigen/include/./unsupported/Eigen/CXX11/Tensor:66,
from file430864722709.cpp:2:
C:/RBuildTools/3.5/mingw_64/x86_64-w64-mingw32/include/wingdi.h:75:0: note: this is the location of the previous definition
#define ERROR 0
^
In file included from F:/R-3.6.3/library/RcppEigen/include/RcppEigen.h:27:0,
from file430864722709.cpp:8:
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:209:37: warning: 'typedef' was ignored in this declaration
typedef typename Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:209:13: error: 'struct Eigen::Map<Eigen::Matrix<Scalar, -1, 1> >' redeclared with different access
typedef typename Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:224:37: warning: 'typedef' was ignored in this declaration
typedef typename Eigen::Map<Eigen::Matrix<T, 1, Eigen::Dynamic> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:224:13: error: 'struct Eigen::Map<Eigen::Matrix<T, 1, -1> >' redeclared with different access
typedef typename Eigen::Map<Eigen::Matrix<T, 1, Eigen::Dynamic> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:238:37: warning: 'typedef' was ignored in this declaration
typedef typename Eigen::Map<Eigen::Array<T, Eigen::Dynamic, 1> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:238:13: error: 'struct Eigen::Map<Eigen::Array<T, -1, 1> >' redeclared with different access
typedef typename Eigen::Map<Eigen::Array<T, Eigen::Dynamic, 1> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:252:37: warning: 'typedef' was ignored in this declaration
typedef typename Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:252:13: error: 'struct Eigen::Map<Eigen::Matrix<LhsScalar, -1, -1, 0> >' redeclared with different access
typedef typename Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:272:37: warning: 'typedef' was ignored in this declaration
typedef typename Eigen::Map<Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:272:13: error: 'struct Eigen::Map<Eigen::Array<T, -1, -1> >' redeclared with different access
typedef typename Eigen::Map<Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic> > OUT ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h: In instantiation of 'struct Rcpp::RcppEigen::is_plain<Eigen::Tensor<double, 2> >':
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:151:17: required from 'SEXPREC* Rcpp::RcppEigen::eigen_wrap(const T&) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*]'
F:/R-3.6.3/library/Rcpp/include/Rcpp/internal/wrap.h:776:56: required from 'SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const T&, Rcpp::traits::true_type) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*; Rcpp::traits::true_type = Rcpp::traits::integral_constant<bool, true>]'
F:/R-3.6.3/library/Rcpp/include/Rcpp/internal/wrap.h:787:89: required from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_importable(const T&, Rcpp::traits::false_type) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*; Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool, false>]'
F:/R-3.6.3/library/Rcpp/include/Rcpp/internal/wrap.h:807:108: required from 'SEXPREC* Rcpp::internal::wrap_dispatch(const T&, Rcpp::traits::wrap_type_unknown_tag) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*]'
F:/R-3.6.3/library/Rcpp/include/Rcpp/internal/wrap_end.h:30:110: required from 'SEXPREC* Rcpp::wrap(const T&) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*]'
file430864722709.cpp:35:55: required from here
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:76:38: error: no type named 'PlainObject' in 'class Eigen::Tensor<double, 2>'
template <typename T> struct is_plain : Rcpp::traits::same_type<T,typename T::PlainObject>{} ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h: In instantiation of 'SEXPREC* Rcpp::RcppEigen::eigen_wrap(const T&) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*]':
F:/R-3.6.3/library/Rcpp/include/Rcpp/internal/wrap.h:776:56: required from 'SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const T&, Rcpp::traits::true_type) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*; Rcpp::traits::true_type = Rcpp::traits::integral_constant<bool, true>]'
F:/R-3.6.3/library/Rcpp/include/Rcpp/internal/wrap.h:787:89: required from 'SEXPREC* Rcpp::internal::wrap_dispatch_unknown_importable(const T&, Rcpp::traits::false_type) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*; Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool, false>]'
F:/R-3.6.3/library/Rcpp/include/Rcpp/internal/wrap.h:807:108: required from 'SEXPREC* Rcpp::internal::wrap_dispatch(const T&, Rcpp::traits::wrap_type_unknown_tag) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*]'
F:/R-3.6.3/library/Rcpp/include/Rcpp/internal/wrap_end.h:30:110: required from 'SEXPREC* Rcpp::wrap(const T&) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*]'
file430864722709.cpp:35:55: required from here
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:151:17: error: no type named 'type' in 'struct Rcpp::RcppEigen::is_plain<Eigen::Tensor<double, 2> >'
) ;
^
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h: In function 'SEXPREC* Rcpp::RcppEigen::eigen_wrap(const T&) [with T = Eigen::Tensor<double, 2>; SEXP = SEXPREC*]':
F:/R-3.6.3/library/RcppEigen/include/RcppEigenWrap.h:152:9: warning: control reaches end of non-void function [-Wreturn-type]
}
^
make: *** [F:/R-3.6.3/etc/x64/Makeconf:215: file430864722709.o] Error 1
Error in sourceCpp(code = "\n#include <./unsupported/Eigen/CXX11/Tensor>\n#ifdef Realloc\n#undef Realloc\n#endif\n#include <Rcpp.h>\n#include <RcppCommon.h>\n#include <RcppEigen.h>\n#include <iostream>\n\n// [[Rcpp::depends(RcppEigen)]]\nusing namespace std;\nusing namespace Eigen;\n\n// [[Rcpp::export]]\nTensor<double, 2> tensorContractTest(int n)\n{\n Tensor<double, 3> a(n, n, n); a.setConstant(1.);\n Tensor<double, 1> b(n); b.setConstant(1.);\n auto indexPair = Eigen::array<IndexPair<int>, 1>{IndexPair<int>(2,0)};\n Tensor<double, 2> result = a.contract(b, indexPair);\n return result;\n}\n") :
Error 1 occurred building shared library.
有人可以帮我解决问题吗?