![](/img/trans.png)
[英]C++ with a math library like GSL, LAPACK, or CBLAS performance vs C++ with Rinside with an R function?
[英]C++ / R: RInside in Windows 7 machine
這個問題與: C ++和R:創建一個.so或.dll加上我已經閱讀了以下帖子的問題和回復:
我嘗試運行提供的代碼作為提供的答案中的示例
#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
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依賴的兩個相關環境變量(如FAQ文件中所述 )
有什么建議嗎? 我需要為每個要編譯的cpp
文件做一個Makefile
嗎?
錯誤在於您的方法。 你做了
R CMD SHLIB final.cpp
這是無處給出與工作正確的做法RInside 。
因為我們需要告訴R一些組件的頭文件和庫 ,所以您應該
cd inst/examples/standard
make # build all
要么
make rinside_sample3 # build just this
或者,如果您使用的是該操作系統,
make -f Makefile.win # all
要么
make -f Makefile.win rinside_sample3
因為Makefile
告訴R在哪里找到它。 這也回答了您的第二個問題:每個目錄一個Makefile
。 再看一下 Makefile
:它設置了幾個 include偽指令; 您的方法僅處理Rcpp,因此當然會出現有關RInside.h
的錯誤。
我認為您不斷重復問同樣的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.