1
我試圖用G ++從以下方式RTools從RInside \在Windows 7 X64的例子\標準目錄建立rinside_sample1.cpp:多重定義錯誤建築RInside樣品
set RCPP=%R_HOME%\library\Rcpp
set RINSIDE=%R_HOME%\library\RInside
g++ -c -m64 rinside_sample1.cpp -I %RINSIDE%\include -I %RCPP%\include -I %R_HOME%\include
g++ -m64 rinside_sample1.o -o rinside_sample1.exe -L %RINSIDE%\libs\x64 -l RInside -L %RCPP%\libs\x64 -l Rcpp -L %R_HOME%\bin\x64 -l R
的聯動結果到了多重定義錯誤:
d000026.o:(.idata$5+0x0): multiple definition of `__imp__ZTVN4Rcpp7RObjectE'
d000019.o:(.idata$5+0x0): first defined here
d000026.o:(.idata$6+0x0): multiple definition of `__nm__ZTVN4Rcpp7RObjectE'
d000019.o:(.idata$6+0x0): first defined here
collect2: ld returned 1 exit status
然而,對於rinside_sample0.cpp succeedes類似的建設進程。有沒有人有解決方案的想法?
似乎rinside_sample1.cpp的問題出現是因爲Rcpp :: NumericMatrix和Rcpp :: NumericVector的用法。
rinside_sample0.cpp代碼:
// -*- 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);
}
rinside_sample1.cpp代碼:
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
//
// Simple example with data in C++ that is passed to R, processed and a result is extracted
//
// Copyright (C) 2009 Dirk Eddelbuettel
// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
//
// GPL'ed
#include <RInside.h> // for the embedded R via RInside
Rcpp::NumericMatrix createMatrix(const int n) {
Rcpp::NumericMatrix M(n,n);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
M(i,j) = i*10 + j;
}
}
return(M);
}
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
const int mdim = 4; // let the matrices be 4 by 4; create, fill
R["M"] = createMatrix(mdim); // then assign data Matrix to R's 'M' var
std::string str =
"cat('Running ls()\n'); print(ls()); "
"cat('Showing M\n'); print(M); "
"cat('Showing colSums()\n'); Z <- colSums(M); print(Z); "
"Z"; // returns Z
Rcpp::NumericVector v = R.parseEval(str); // eval string, Z then assigned to num. vec
for (int i=0; i< v.size(); i++) { // show the result
std::cout << "In C++ element " << i << " is " << v[i] << std::endl;
}
exit(0);
}
由於我使用x64版本,我已取消註釋'R_ARCH:= - Makefile.win中的--arch x64'行。不幸的是,它產生了'RINSIDELIBS'的錯誤值,我得到了'g ++ -m64 -IC:/R/R-2.15.1/include -IC:/R/R-2.15.1/include/x64 -IC:/ R /R-2.15.1/library/Rcpp/include -IC:/R/R-2.15.1/library/RInside/include -O2 -Wall -mtune = core2 -Wall -s rinside_sample3.cpp -LC:/ R/R-2.15.1/bin/x64 -lR -LC:/R/R-2.15.1/bin/x64-1lbblas -LC:/R/R-2.15.1/bin/x64 -lRlapack「/libRInside.a 「C:/R/R-2.15.1/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample1 g ++。exe:error:/libRInside.a:沒有這樣的文件或目錄。 – 2012-07-31 21:42:49
在'R_ARCH:= --arch i386'情況下沒有這樣的問題。然而,正確的構建命令x64現在很清楚 - 感謝您的幫助! – 2012-07-31 21:44:32
我的印象是當前的R和當前Rtools for Windows可以無縫地構建32位和64位。 – 2012-07-31 21:49:28