2012-07-31 4 views
1

:여러 정의 오류 건물 RInside 샘플 나는 다음과 같은 방법으로 RTools에서 ++ g을 사용하여 RInside 윈도우 7의 x64 표준 디렉토리 예에서 rinside_sample1.cpp를 구축하기 위해 노력하고있어

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 

여러 정의 오류로 연결 결과 : rinside_sample0.cpp의 succeedes에 대한

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_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); 
} 

답변

1

은 내가 제공 한 Makefile을 사용하지 않고있는이 작동하는 이유가 있나요? 그냥 내 컴퓨터에, 그 후에 우리가 Windows에서 동일하게 작동

[email protected]:~/svn/rinside/pkg/inst/examples/standard$ ./rinside_sample1 
Running ls() 
[1] "argv" "M" 
Showing M 
    [,1] [,2] [,3] [,4] 
[1,] 0 1 2 3 
[2,] 10 11 12 13 
[3,] 20 21 22 23 
[4,] 30 31 32 33 
Showing colSums() 
[1] 60 64 68 72 
In C++ element 0 is 60 
In C++ element 1 is 64 
In C++ element 2 is 68 
In C++ element 3 is 72 
[email protected]:~/svn/rinside/pkg/inst/examples/standard$ 

을 할 수

[email protected]:~/svn/rinside/pkg/inst/examples/standard$ make rinside_sample1 
g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \ 
    -I/usr/local/lib/R/site-library/RInside/include -O3 -pipe -g -Wall \ 
    rinside_sample1.cpp -L/usr/lib/R/lib -lR -lblas -llapack \ 
    -L/usr/local/lib/R/site-library/Rcpp/lib \ 
    -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib \ 
    -L/usr/local/lib/R/site-library/RInside/lib \ 
    -lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib \ 
    -o rinside_sample1 
[email protected]:~/svn/rinside/pkg/inst/examples/standard$ 

에 이르게하는

make rinside_sample1 

말,하지만 당신은

을 할 필요가
make -f Makefile.win rinside_sample1 
+0

x64 버전을 사용할 때 나는'R_ARCH : = --arch x64'라인을 Makefile.win에 넣는다. 불행히도'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 -lRLC : /R/R-2.15.1/bin/x64 -lRblas -LC : /R/R-2.15.1/bin/x64 -lRapack "/libRInside.a "C : /R/R-2.15.1/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample1 g ++ .exe : 오류 : /libRInside.a : 해당 파일이나 디렉터리가 없습니다. –

+0

'R_ARCH : = --arch i386'의 경우에는 그런 문제가 없습니다. 그러나 x64에 대한 적절한 빌드 명령은 현재 분명합니다 - 도움을 주셔서 감사합니다! –

+0

저는 Windows 용 현재 R과 현재 Rtools가 32 비트와 64 비트를 완벽하게 구현한다는 인상을 받았습니다. –