问题描述
此问题与以下内容有关:,此外,我已经阅读了以下帖子的问题和答复:
This question is related to: C++ and R: Create a .so or .dll plus i have read the questions and replies of these posts:
- Compiling RInside programs on Windows
- Problem with compiling RInside examples under Windows
我尝试运行提供的示例中提供的代码
I try to run the code provided as an example in the answer provided
#include <RInside.h> // for the embedded R via RInside
#include <iomanip>
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
std::string txt = // load library, run regression, create summary
"suppressMessages(require(stats));"
"swisssum <- summary(lm(Fertility ~ . , data = swiss));"
"print(swisssum)";
R.parseEvalQ(txt); // eval command, no return
// evaluate R expressions, and assign directly into Rcpp types
Rcpp::NumericMatrix M( (SEXP) R.parseEval("swcoef <- coef(swisssum)"));
Rcpp::StringVector cnames( (SEXP) R.parseEval("colnames(swcoef)"));
Rcpp::StringVector rnames( (SEXP) R.parseEval("rownames(swcoef)"));
std::cout << "\n\nAnd now from C++\n\n\t\t\t";
for (int i=0; i<cnames.size(); i++) {
std::cout << std::setw(11) << cnames[i] << "\t";
}
std::cout << std::endl;
for (int i=0; i<rnames.size(); i++) {
std::cout << std::setw(16) << rnames[i] << "\t";
for (int j=0; j<cnames.size(); j++) {
std::cout << std::setw(11) << M(i,j) << "\t";
}
std::cout << std::endl;
}
std::cout << std::endl;
exit(0);
}
CMD中的错误如下
C:\Users\DON\Desktop>R CMD SHLIB final.cpp
g++ -m64 -I"C:/R/R-3.2.4/include" -DNDEBUG -I"d:/RCompile/r-compiling/local/
local323/include" -O2 -Wall -mtune=core2 -c final.cpp -o final.o
final.cpp:1:74: fatal error: RInside.h: No such file or directory
compilation terminated.
make: *** [final.o] Error 1
Warning message:
comando ejecutado 'make -f "C:/R/R-3.2.4/etc/x64/Makeconf" -f "C:/R/R-3.2.4/shar
e/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)
' SHLIB="final.dll" WIN=64 TCLBIN=64 OBJECTS="final.o"' tiene estatus 2
显然,它找不到 RInside.h
标头。我将R安装在没有空格的文件夹中。全局变量中的PATH具有: C:\R\R-3.2.4\bin; C:\Rtools\bin; C:\Rtools\gcc-4.6.3\bin
Clearly it cant find the RInside.h
header. I have the R installed in a folder without spaces. The PATH in global variables have: C:\R\R-3.2.4\bin; C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin
我了解CMD我无法引入这样的命令
I understand that in the CMD i cant introduce comands like
$ export PKG_LIBS=‘Rscript -e "Rcpp:::LdFlags()"‘ # if Rcpp older than 0.11.0
$ export PKG_CXXFLAGS=‘Rscript -e "Rcpp:::CxxFlags()"‘
首先定义并导出R CMD SHLIB依赖的两个相关环境变量(如)
Which first defines and exports two relevant environment variables which R CMD SHLIB then relies on (as put in the FAQ file)
对此有何建议?我需要为要编译的每个 cpp
文件做一个 Makefile
吗?
Any advice on this? I need to do a Makefile
for each cpp
file that i want to compile?
推荐答案
错误在于您的方法。您确实
The error is in your approach. You did
R CMD SHLIB final.cpp
无处是使用。
因为我们需要向R讲解几个组件的标头和库,所以您应该
cd inst/examples/standard
make # build all
或
make rinside_sample3 # build just this
,或者,如果您使用的是该操作系统,
or, if you're on that OS,
make -f Makefile.win # all
或
make -f Makefile.win rinside_sample3
as Makefile
告诉R在哪里找到它。这也回答了您的第二个问题:每个目录一个 Makefile
即可。然后在 Makefile
中查找 :它设置几个 include指令;您的方法只处理了Rcpp,因此当然您会得到关于 RInside.h
的错误。
as the Makefile
tells R where do find this. That also answers your second question: One Makefile
per directory will do. And look at the Makefile
: it sets several include directives; your approach only dealt with Rcpp so of course you get an error about RInside.h
not found.
我想你不断重复问同样的问题。
I think you keep asking the same question over and over.
这篇关于C ++ / R:Windows 7计算机中的RInside的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!