【问题标题】:Fatal error for <RInside.h><RInside.h> 的致命错误
【发布时间】:2018-06-27 06:49:20
【问题描述】:

我正在通过终端运行这个示例。但是该行出现fatal error: RInside.h: No such file or directory 错误,#include&lt;RInside.h&gt;。 它是从 C++ 到 R 的接口。我在 R 中有 RInside 包。 我的代码:

#include<iostream>
#include<RInside.h>
using namespace std;
int main(){
    int a=12;
    cout<<a<<endl;
    return 0;  
}

#include&lt;Rcpp.h&gt; 标头出现同样的错误。

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
NumericVector callFunction(NumericVector x, Function f) {
    NumericVector res = f(x);
    return res;
}

Package RInside 0.2.14 版

包 Rcpp 版本 0.12.17

【问题讨论】:

  • 在您的文件系统上找到这些头文件并确保它们对编译器可见(它们在编译器检查头文件的路径列表中)。另外,什么操作系统?

标签: c++ r rcpp rinside


【解决方案1】:

RInside 随附在 examples 文件夹中的 GNUmakefile 包含以下内容:

## comment this out if you need a different version of R, 
## and set set R_HOME accordingly as an environment variable
R_HOME :=       $(shell R RHOME)

[...]
## include headers and libraries for R 
RCPPFLAGS :=        $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS :=        $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK :=      $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)

## if you need to set an rpath to R itself, also uncomment
#RRPATH :=      -Wl,-rpath,$(R_HOME)/lib

## include headers and libraries for Rcpp interface classes
## note that RCPPLIBS will be empty with Rcpp (>= 0.11.0) and can be omitted
RCPPINCL :=         $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RCPPLIBS :=         $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)


## include headers and libraries for RInside embedding classes
RINSIDEINCL :=      $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS :=      $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)

## compiler etc settings used in default make rules
CXX :=          $(shell $(R_HOME)/bin/R CMD config CXX)
CPPFLAGS :=         -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
CXXFLAGS :=         $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
LDLIBS :=       $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)

如果您使用 GNU make,您可能可以按字面意思使用它。否则,您将不得不根据您的构建环境对其进行调整。请查看提供的示例以了解更多详细信息。

【讨论】:

  • 我试过这个。 stackoverflow.com/a/21225890/9113303 通过 R studio 并在运行时我刚刚得到 Rcpp::sourceCpp('Desktop/cuda_pgm_cpp/mySum.cpp') 作为输出,但如何获取返回值。我正在通过函数传递 2 个参数。
  • @Aswathy 这个关于RInside 的问题有什么关系?你想明确做什么?
  • :尝试从 c++ 调用 R 函数(带有传递参数),因为 Rcpp 和 RInside 是有用的包。
  • @Aswathy 你看过RInside 附带的例子了吗?如果这些没有提供足够的详细信息,那么您应该为您正在尝试做的事情提供minimal reproducible example
【解决方案2】:

使用 g++ 编译 RInside 时应指定头文件的路径。在 Mac OS X (10.14.2 Mojave) 上有一个 g++ 的参数列表供您参考,希望对您有所帮助。

g++ 
-I/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RInside/include \
-I/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include \
-I/Library/Frameworks/R.framework/Versions/3.5/Resources/include \
-L/Library/Frameworks/R.framework/Versions/3.5/Resources/lib \
-L/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RInside/lib \
-lR -lRInside -O3 -o test helloworld_rinside.cpp

“helloworld_rinside.cpp”源代码,http://dirk.eddelbuettel.com/code/rinside.html

// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
//
// Simple example showing how to do the standard 'hello, world' using embedded R
//
// Copyright (C) 2009 Dirk Eddelbuettel
// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
//
// GPL'ed

#include <RInside.h> // for the embedded R via RInside

int main(int argc, char *argv[]) {

  RInside R(argc, argv); // create an embedded R instance

  R["txt"] = "Hello, world!\n"; // assign a char* (string) to 'txt'

  R.parseEvalQ("cat(txt)"); // eval the init string, ignoring any returns

  exit(0);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-16
    • 2017-06-08
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多