Unable to link external lib (CLAPACK) using MATLAB mex -
i'm new mex , problem spent me days still cannot figure out do.
i create la_test.cpp file test 1 of subroutines in clapck: cgemm_ (complex matrix-matrix multiplication). here code:
#include "mex.h" #include "matrix.h" #include <string.h> #include <stdlib.h> #include <malloc.h> #include <iostream> #include <stdio.h> #include "f2c.h" #include "clapack.h" void mexfunction(int nlhs, mxarray *plhs[], int nrhs, const mxarray *prhs[]) { float *xr,*xi; // store input data float *zsr,*zsi; // store output long int m,n; complex *a; xr = (float *) mxgetpr(prhs[0]); xi = (float *) mxgetpi(prhs[0]); size_t k = mxgetnumberofdimensions(prhs[0]); const int *size = mxgetdimensions(prhs[0]); m = mxgetm(prhs[0]); n = mxgetn(prhs[0]); = new complex[m*n]; complex 1 = {1.0f, 0.0f}, 0 = {0.0f, 0.0f}; (int i=0; i<m; i++){ (int j=0; j<n; j++){ complex rc = {xr[j + n*i], xi[j + n*i]}; a[j + n*i] = rc; } } plhs[0] =(mxarray *) mxcreatedoublematrix( n, n, mxcomplex ); zsr = (float *) mxgetpr(plhs[0]); zsi = (float *) mxgetpi(plhs[0]); complex *ata = 0; ata = new complex[n*n]; char *chn = "n"; char *chc = "c"; cgemm_(chc, chn, &n, &n, &m, &one, a, &m, a, &m, &zero, ata, &n); (int i=0; i<m; i++){ (int j=0; j<n; j++){ zsr[j + n*i] = ata[j + n*i].r; zsi[j + n*i] = ata[j + n*i].i; } } }
basically, store input matrix , try compute a'*a. header files: f2c.h, clapack.h 3 64bit libraries: blas.lib, libf2c.lib , lapack.lib http://icl.eecs.utk.edu/lapack-for-windows/clapack/index.html#install in same file of la_test.cpp. i'm working on windows 7 64bit system matlab r2013a , visual studio 2012.
i have tried both:
mex la_test.cpp lapack.lib libf2c.lib blas.lib
and
mex -llapack -llibf2c -lblas -l"c:\users\ziwu\desktop\la_test" la_test.cpp
all following error:
creating library c:\users\ziwu\appdata\local\temp\mex_epl230\templib.x , object c:\users\ziwu\appdata\local\temp\mex_epl230\templib.exp la_test.obj : error lnk2019: unresolved external symbol cgemm_ referenced in function mexfunction la_test.mexw64 : fatal error lnk1120: 1 unresolved externals
i've checked on internet long time, found no solution yet!
please me if have advice.
Comments
Post a Comment