首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 ><RInside.h>的致命错误

<RInside.h>的致命错误
EN

Stack Overflow用户
提问于 2018-06-27 06:49:20
回答 2查看 565关注 0票数 0

我正在运行这个例子,通过终端。但是得到了行的fatal error: RInside.h: No such file or directory错误,#include<RInside.h>。它是从c++到R的接口。我在R中有RInside包,我的代码:

代码语言:javascript
复制
#include<iostream>
#include<RInside.h>
using namespace std;
int main(){
    int a=12;
    cout<<a<<endl;
    return 0;  
}

同样的错误发生在#include<Rcpp.h>头上。

代码语言:javascript
复制
#include <Rcpp.h>

using namespace Rcpp;

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

软件包RInside版本0.2.14

软件包Rcpp版本0.12.17

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-27 08:57:52

RInside附带的RInside文件夹中的examples包括如下内容:

代码语言:javascript
复制
## 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,您可能可以使用这个字面意思。否则,您将不得不调整它以适应您的构建环境。有关更多细节,请参阅所提供的例子。

票数 2
EN

Stack Overflow用户

发布于 2019-02-03 15:51:49

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

代码语言:javascript
复制
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源代码

代码语言:javascript
复制
// -*- 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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51056252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档