首页 > 解决方案 > 错误:在执行“R CMD INSTALL”时,“结果”没有命名类型

问题描述

我有一个从 c++ 函数返回的用户定义对象,该对象是使用 Rstudio 中的 Rcpp 库在 R 代码中访问的。

当使用“R CMD INSTALL”在 opencpu 上构建和部署 R 包时,g++ 编译器会抛出错误:“Result”没有命名类型。

'Result' 是一个 c++ 类,由 c++ 代码返回给调用 R 代码。我认为 R 不识别这个 c++ 类,但在键入自动完成时显示 Result 类。

我不明白为什么命令“R CMD INSTALL”没有按预期执行和安装。

rcpp.c 文件

#include <Rcpp.h>
#include "Engine.h"
#include "Result.h"
using namespace Rcpp;
using Engine::execute;
// [[Rcpp::export]]
List rcpp_hello_world() {

    CharacterVector x = CharacterVector::create( "foo", "bar" )  ;
    NumericVector y   = NumericVector::create( 0.0, 1.0 ) ;
    List z            = List::create( x, y ) ;

    return z ;
}

// [[Rcpp::export]]
Result execute(){
  printf("In cpp call!!");
  ForecastingModel *fm;
  InputData *sid;
  int i=1;
  int j=1;
  utils::Time *startTime;
  utils::Time *endTime;
  return Engine::execute(*fm,*sid,i,j,*startTime,*endTime);
}

c++文件

#ifndef RESULT_H
#define RESULT_H

#include<string>
#include<vector>
class Result
 {
 private:

   int status ;
   std::vector<double> forecast;
   std::string dataproblem ;
  public:

  std::string getDataproblem( );
  void setDataproblem(std::string);
  void setForecast(std::vector<double> );
  std::vector<double>& getForecast();
  int getStatus( );
  void setStatus(int);
 };
 #endif

任何帮助表示赞赏。谢谢!

标签: c++rrcpp

解决方案


推荐阅读