1

I'm new to mex and this problem spent me days but I still cannot figure out what to do.

I create la_test.cpp file to test one of the subroutines in CLAPCK: cgemm_ (complex matrix-matrix multiplication). Here is the 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; // To store the input data
float *zsr,*zsi; // To store the 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]); 

A = new complex[m*n];
complex one = {1.0f, 0.0f}, zero = {0.0f, 0.0f};

for (int i=0; i<m; i++){
     for (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);

for (int i=0; i<m; i++){
       for (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, I store input matrix into A and try to compute A'*A. Header files: f2c.h, clapack.h as well as three 64bit libraries: blas.lib, libf2c.lib and lapack.lib from http://icl.eecs.utk.edu/lapack-for-windows/clapack/index.html#install are all in the same file of la_test.cpp. I'm working on Windows 7 64bit system with matlab r2013a and Visual Studio 2012.

I have tried with 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 with following error:

Creating library C:\Users\Ziwu\AppData\Local\Temp\mex_epl230\templib.x and 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 for long time, but found no solution yet!

Please help me if you have any advice.

0 Answers0