2012-11-23 2 views
1

예제 mex 및 armadillo 프로그램을 컴파일하는 데 어려움을 겪고 있으며 누구든지 나를 도와 줄 수 있는지 궁금합니다. Mac OS를 사용하고 있으며 설치가 성공적이었습니다.Mex and Armadillo 컴파일에 어려움이 있습니다.

코드 :

#include "mex.h" 
#include "math.h" 
#include<armadillo> 


using namespace arma; 

void matlab2arma(mat& A, const mxArray *mxdata){ 
// delete [] A.mem; // don't do this! 
access::rw(A.mem)=mxGetPr(mxdata); 
access::rw(A.n_rows)=mxGetM(mxdata); // transposed! 
access::rw(A.n_cols)=mxGetN(mxdata); 
access::rw(A.n_elem)=A.n_rows*A.n_cols; 
}; 

void freeVar(mat& A, const double *ptr){ 
access::rw(A.mem)=ptr; 
access::rw(A.n_rows)=1; // transposed! 
access::rw(A.n_cols)=1; 
access::rw(A.n_elem)=1; 
}; 

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{ 
if (nrhs != 2) 
mexErrMsgTxt("Incorrect number of input arguments"); 
if (nlhs != 1) 
mexErrMsgTxt("Incorrect number of output arguments"); 

mat D1(1,1); 
const double* D1mem=access::rw(D1.mem); 
matlab2arma(D1,prhs[0]); // First create the matrix, then change it to point to the matlab data. 

mat D2(1,1); 
const double* D2mem=access::rw(D2.mem); 
matlab2arma(D2,prhs[1]); 

// check if the input corresponds to what you are expecting 
if(D1.n_rows != D2.n_rows) 
mexErrMsgTxt("Columns of D1 and D2 must be of equal length!"); 

if(D1.n_cols != D2.n_cols) 
mexErrMsgTxt("Rows of D1 and D2 must be of equal length!"); 

plhs[0] = mxCreateDoubleMatrix(D1.n_rows, D1.n_cols, mxREAL); 
mat output(1,1); 
const double* outputmem=access::rw(output.mem); 
matlab2arma(output,plhs[0]); 

output=D1+D2; 
// output.print(); 

freeVar(D1,D1mem); // Change back the pointers!! 
freeVar(D2,D2mem); 
freeVar(output,outputmem); 
return; 
} 
+1

컴파일러 오류 당신은 무엇을 얻을거야? – Isaac

+0

mex -I/Library/armadillo-3.4.4/include/-lblas -llapack example1.cpp example1.cpp : 'void matlab2arma (arma :: mat &, const mxArray *)'함수에서 : example1.cpp : 9 : 오류 : '액세스'이 선언되지 않았습니다. example1.cpp : 9 : 오류 : 'rw'가이 범위에서 선언되지 않았습니다. example1.cpp : 10 : 오류 : '액세스'가 선언되지 않았습니다. example1.cpp : 11 : 오류 : '액세스'가 선언되지 않았습니다. example1.cpp : 12 : 오류 : '액세스'가 선언되지 않았습니다. example1.cpp : 'void freeVar (arma :: mat &, const double *)'함수에서 : ??? 208 ==> mex at 208을 사용하는 중 오류가 발생했습니다. 성공적으로 완료 할 수 없습니다. –

+0

어디에서 오는 'access' 네임 스페이스가 있습니까? – Isaac

답변

1

그것은 내 시스템에 작업을 수행합니다 (우분투 12.04, 64 비트, MatlabR2013a, g ++) 다음과 같은 컴파일 명령을 사용하여 :

mex mexTest.cpp -llapack -larmadillo -lblas 

가 mexTest.cpp가 포함 코드 스 니펫을 제공해야합니다. Matlab에서 Armadillo를 올바르게 컴파일하려면 라이브러리 경로가 올바르게 설정되어 있어야합니다. 이 파일은 mexopts.sh에서 업데이트하거나 $ matlabroot/sys/os/XXXXX의 심볼릭 링크를 리디렉션하여 업데이트 할 수 있습니다. 여기서 XXXXX는 시스템에 따라 다를 수 있습니다 (32/64 비트 & OS). 당신이 딜을 올바르게 설정 한 경우

0

, 바로 다음 충분하고 (코드는 나를 위해 성공적 일) :

mex your_code.cpp -larmadillo