【发布时间】:2016-09-26 23:20:23
【问题描述】:
我正在尝试编写一个 R 包,它是使用 RcppGSL 的 C++ 库的包装器。我已经成功安装了gsl,并且包检查在Rcpp函数编译处停止:
#include <Rcpp.h>
#include <RcppGSL.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <stdlib.h>
#include "graphm-0.52/graph.h"
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_permutation.h>
using namespace std;
using namespace Rcpp;
// declare a dependency on the RcppGSL package; also activates plugin
// (but not needed when ’LinkingTo: RcppGSL’ is used with a package)
//
// [[Rcpp::depends(RcppGSL)]]
//
//
// [[Rcpp::export]]
Rcpp::List run_graph_match(const RcppGSL::Matrix & A, const RcppGSL::Matrix & B, const Rcpp::List &algorithm_params ){
graph graphm_obj_A;
graphm_obj_A.set_adjmatrix (((*A)));
graph graphm_obj_B;
graphm_obj_B.set_adjmatrix (((*B)));
}
函数 graph::set_adjmatrix (const gsl_matrix* A) 接受一个 const gsl_matrix 指针。 我的问题是,从 const RcppGSL::Matrix 引用到 const gsl_matrix 指针,我需要的正确引用级别是多少。我想只有一个,但我收到以下错误
graphmatch_rcpp.cpp:31:34: error: no matching function for call to 'graph::set_adjmatrix(RcppGSL::matrix<double>::gsltype&)'
graphm_obj_A.set_adjmatrix((*A)));
^
graphmatch_rcpp.cpp:31:34: note: candidate is:
In file included from graphmatch_rcpp.cpp:9:0:
graphm-0.52/graph.h:52:9: note: int graph::set_adjmatrix(const gsl_matrix*)
int set_adjmatrix(const gsl_matrix* _gm_A);
^
graphm-0.52/graph.h:52:9: note: no known conversion for argument 1 from 'RcppGSL::matrix<double>::gsltype {aka gsl_matrix}' to 'const gsl_matrix*'
graphmatch_rcpp.cpp:33:34: error: no matching function for call to 'graph::set_adjmatrix(RcppGSL::matrix<double>::gsltype&)'
graphm_obj_B.set_adjmatrix((*B)));
这表明我应该再次引用它并转换为 const 指针。从 RcppGSL::matrix 到 gsl_matrix 有一些隐式转换,所以我不确定我是否理解细节。任何更熟悉 RcppGSL, Rcpp 的人都可以回答我如何将 RcppGSL::matrix & 传递给 'const gsl_matrix*' 吗?
【问题讨论】: