Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: compiling C file: error LNK2019: unresolved external symbol

$
0
0
"Charles Behr" <behr_charles@hotmail.com> wrote in message <k6mqbk$dp5$1@newscl01ah.mathworks.com>...

(snip)

> fast_kmeans_step.obj : error LNK2019: unresolved external symbol PTR_dgemm referenced in function minus2xty
> fast_kmeans_step.mexw64 : fatal error LNK1120: 1 unresolved externals
>
> C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'fast_kmeans_step.mexw64' failed.

I see this line:

  dgemm(&cht, &chn, &mcols, &ncols, &drows, &minus2,
            vects1, &drows, vects2, &drows, &one, output, &mcols);

in the code that I found here:

http://code.google.com/p/spiky/source/browse/spike_sorting/mex/fast_kmeans_step.c?r=64

So the code attempts to call the BLAS routine dgemm (double precision generic matrix multiply). But I don't see any prototype information for dgemm in the code. And you get an error for a missing PTR_dgemm routine. My *guess* is that dgemm has been defined as PTR_dgemm somewhere??? But maybe PTR_dgemm didn't get defined to anything??? Just guesses at this point. Basically, dgemm needs to be either left as dgemm (e.g., for Windows), or defined to be dgemm_ (e.g., for Unix) so that it will match what is actualy in the BLAS library when linked.

HOWEVER, even if you get this part figured out and compiled/linked OK, I strongly suspect that the resulting mex routine will bomb. That is because the type for the integer arguments in the dgemm call are hard-coded above to be int's (very likely 32-bit), but on your 64-bit system the integer arguments in the dgemm call may actually be size_t (very likely 64-bit) in the 64-bit library. So I would not expect the compiled code to work on a 64-bit system even if it did compile and link OK. You would have to manually go in and change all of the integer arguments being passed into the dgemm function to be mwSignedIndex instead of int. E.g., this:

/* Function: minus2xty(double *,double *,double *,PTR_dgemm,int,int,int)
 * ------------------------------------------------------------------
 * Subtracts 2*vects1(:,i)*vects2(:,i)' from each element of output. */
  void minus2xty(double* output, double *vects1, double *vects2,
                 int mcols, int ncols, int drows)
{
    int i, numel;
    double minus2 = -2.0, one = 1.0;

    char chn = 'N', cht = 'T';
      dgemm(&cht, &chn, &mcols, &ncols, &drows, &minus2,
            vects1, &drows, vects2, &drows, &one, output, &mcols);
      numel = ncols*mcols;
    for (i = 0; i < numel; i++) { // Fix roundoff error ...
      if (output[i] < 0) {output[i] = 0;}
    }
}


should be changed to something like this:


/* Function: minus2xty(double *,double *,double *,PTR_dgemm,int,int,int)
 * ------------------------------------------------------------------
 * Subtracts 2*vects1(:,i)*vects2(:,i)' from each element of output. */
  void minus2xty(double* output, double *vects1, double *vects2,
                 int mcols, int ncols, int drows)
{
    int i, numel;
    double minus2 = -2.0, one = 1.0;
    mwSignedIndex mcolsx = mcols, ncolsx = ncols, drowsx = drows;

    char chn = 'N', cht = 'T';
      dgemm(&cht, &chn, &mcolsx, &ncolsx, &drowsx, &minus2,
            vects1, &drowsx, vects2, &drowsx, &one, output, &mcolsx);
      numel = ncols*mcols;
    for (i = 0; i < numel; i++) { // Fix roundoff error ...
      if (output[i] < 0) {output[i] = 0;}
    }
}


James Tursa

Viewing all articles
Browse latest Browse all 19628

Trending Articles