我正在通过终端运行此示例。但是该行fatal error: RInside.h: No such file or directory
发生#include<RInside.h>
错误。
它是从c ++到R的接口。我在R中有 RInside 软件包。
我的代码:
#include<iostream>
#include<RInside.h>
using namespace std;
int main(){
int a=12;
cout<<a<<endl;
return 0;
}
#include<Rcpp.h>
标头出现相同的错误。
#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
答案 0 :(得分:2)
GNUmakefile
文件夹中的RInside
附带的examples
包括以下内容:
## 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,则可以按字面意义使用它。否则,您将不得不对其进行调整以适合您的构建环境。请查看提供的示例以获取更多详细信息。
答案 1 :(得分:0)
使用g ++编译RInside时,应指定头文件的路径。在Mac OS X(10.14.2 Mojave)上有一个g ++参数列表供您参考,希望对您有所帮助。
BrandID
“ helloworld_rinside.cpp”的源代码,http://dirk.eddelbuettel.com/code/rinside.html
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