C++ C++;/R:Windows 7机器中的清洗液
这个问题涉及:另外,我已经阅读了这些帖子的问题和回复: 我尝试运行所提供的代码,作为所提供答案中的示例C++ C++;/R:Windows 7机器中的清洗液,c++,r,windows,compilation,rcpp,C++,R,Windows,Compilation,Rcpp,这个问题涉及:另外,我已经阅读了这些帖子的问题和回复: 我尝试运行所提供的代码,作为所提供答案中的示例 #include <RInside.h> // for the embedded R via RInside #include <iomanip> int main(int argc, char *argv[]) { RInside R(argc, argv); // create an emb
#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);
}
显然,它找不到RInside.h
标题。我将R安装在一个没有空格的文件夹中。全局变量中的路径有:C:\R\R-3.2.4\bin;C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin
我知道在CMD中我不能介绍像
$ export PKG_LIBS=‘Rscript -e "Rcpp:::LdFlags()"‘ # if Rcpp older than 0.11.0
$ export PKG_CXXFLAGS=‘Rscript -e "Rcpp:::CxxFlags()"‘
它首先定义并导出两个相关的环境变量,然后R CMD SHLIB依赖于这两个环境变量(如
有什么建议吗?我需要为我要编译的每个
cpp
文件执行Makefile
?错误在您的方法中。是的
R CMD SHLIB final.cpp
这是没有给出的正确方法与
因为我们需要告诉R关于几个组件的头和库,所以您应该
cd inst/examples/standard
make # build all
或
或者,如果你在那个操作系统上
make -f Makefile.win # all
或
正如Makefile
告诉R在哪里可以找到这个。这也回答了您的第二个问题:每个目录一个Makefile
就可以了。看看Makefile
:它设置了几个include指令;您的方法只处理Rcpp,因此您当然会得到一个关于RInside.h
未找到的错误
我想你一直在反复问同一个问题 错误在你的方法中。是的
R CMD SHLIB final.cpp
这是没有给出的正确方法与
因为我们需要告诉R关于几个组件的头和库,所以您应该
cd inst/examples/standard
make # build all
或
或者,如果你在那个操作系统上
make -f Makefile.win # all
或
正如Makefile
告诉R在哪里可以找到这个。这也回答了您的第二个问题:每个目录一个Makefile
就可以了。看看Makefile
:它设置了几个include指令;您的方法只处理Rcpp,因此您当然会得到一个关于RInside.h
未找到的错误
我想你一直在反复问同一个问题 输出是exe而不是dll。所以当你在C++中有R代码时,没有DLL或者可以这样做吗?请重新阅读RInside所做的,以及Rcpp和其他扩展的内容。从RInside获取
.exe
是一项非常重要的功能。也许我需要买你的书:)谢谢输出是一个exe而不是dll。所以当你在C++中有R代码时,没有DLL或者可以这样做吗?请重新阅读RInside所做的,以及Rcpp和其他扩展的内容。从RInside获得.exe
是一项非常重要的功能。也许我需要买你的书:)谢谢