Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
3.22/5 (2 votes)
See more:
hi i'm using matlab 2013a 64bit and win7 x64.
try compile mex file (resize.cc).


>> mex -setup

Welcome to mex -setup.  This utility will help you set up
a default compiler.  For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2013a/win64.html

Please choose your compiler for building MEX-files:

Would you like mex to locate installed compilers [y]/n? y

Select a compiler:
[1] Intel Visual Fortran 13 (with Microsoft Software Development Kit (SDK) linker) in C:\Program Files (x86)\Intel\Composer XE 2013\
[2] Intel Visual Fortran 13.0 (with Microsoft Visual C++ 2012 linker) in C:\Program Files (x86)\Intel\Composer XE 2013
[3] Microsoft Software Development Kit (SDK) 7.1 in C:\Program Files (x86)\Microsoft Visual Studio 10.0
[4] Microsoft Visual C++ 2012 in D:\Program Files (x86)\Microsoft Visual Studio 11.0

[0] None

Compiler: 4

Please verify your choices:

Compiler: Microsoft Visual C++ 2012
Location: D:\Program Files (x86)\Microsoft Visual Studio 11.0

Are these correct [y]/n? y

***************************************************************************
  Warning: MEX-files generated using Microsoft Visual C++ 2012 require
           that Microsoft Visual Studio 2012 run-time libraries be
           available on the computer they are run on.
           If you plan to redistribute your MEX-files to other MATLAB
           users, be sure that they have the run-time libraries.
***************************************************************************


Trying to update options file: C:\Users\AsUs\AppData\Roaming\MathWorks\MATLAB\R2013a\mexopts.bat
From template:              D:\PROGRA~2\MATLAB\R2013a\bin\win64\mexopts\msvc110opts.bat

Done . . .

**************************************************************************
  Warning: The MATLAB C and Fortran API has changed to support MATLAB
           variables with more than 2^32-1 elements.  In the near future
           you will be required to update your code to utilize the new
           API. You can find more information about this at:
           http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html
           Building with the -largeArrayDims option enables the new API.
**************************************************************************

>> mex -O -largeArrayDims resize.cc
resize.cc
resize.cc(36) : error C2057: expected constant expression
resize.cc(36) : error C2466: cannot allocate an array of constant size 0
resize.cc(36) : error C2133: 'ofs' : unknown size
resize.cc(70) : error C3861: 'bzero': identifier not found
resize.cc(85) : error C2440: 'initializing' : cannot convert from 'const mwSize *' to 'const int *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
resize.cc(95) : error C3861: 'round': identifier not found
resize.cc(96) : error C3861: 'round': identifier not found
resize.cc(98) : error C2664: 'mxCreateNumericArray_730' : cannot convert parameter 2 from 'int [3]' to 'const mwSize *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

  D:\PROGRA~2\MATLAB\R2013A\BIN\MEX.PL: Error: Compile of 'resize.cc' failed.

Error using mex (line 206)
Unable to complete successfully.



how do you fix error line 36 resize.cc ?

code (resize.cc):
C++
#include <math.h>
#include <assert.h>
#include <string.h>
#include "mex.h"

/*
 * Fast image subsampling.
 * This is used to construct the feature pyramid.
 */

// struct used for caching interpolation values
struct alphainfo {
  int si, di;
  double alpha;
};

// copy src into dst using pre-computed interpolation values
void alphacopy(double *src, double *dst, struct alphainfo *ofs, int n) {
  struct alphainfo *end = ofs + n;
  while (ofs != end) {
    dst[ofs->di] += ofs->alpha * src[ofs->si];
    ofs++;
  }
}

// resize along each column
// result is transposed, so we can apply it twice for a complete resize
void resize1dtran(double *src, int sheight, double *dst, int dheight,
                  int width, int chan) {
  double scale = (double)dheight/(double)sheight;
  double invscale = (double)sheight/(double)dheight;

  // we cache the interpolation values since they can be
  // shared among different columns
  int len = (int)ceil(dheight*invscale) + 2*dheight;
  alphainfo ofs[len];
  int k = 0;
  for (int dy = 0; dy < dheight; dy++) {
    double fsy1 = dy * invscale;
    double fsy2 = fsy1 + invscale;
    int sy1 = (int)ceil(fsy1);
    int sy2 = (int)floor(fsy2);

    if (sy1 - fsy1 > 1e-3) {
      assert(k < len);
      assert(sy-1 >= 0);
      ofs[k].di = dy*width;
      ofs[k].si = sy1-1;
      ofs[k++].alpha = (sy1 - fsy1) * scale;
    }

    for (int sy = sy1; sy < sy2; sy++) {
      assert(k < len);
      assert(sy < sheight);
      ofs[k].di = dy*width;
      ofs[k].si = sy;
      ofs[k++].alpha = scale;
    }

    if (fsy2 - sy2 > 1e-3) {
      assert(k < len);
      assert(sy2 < sheight);
      ofs[k].di = dy*width;
      ofs[k].si = sy2;
      ofs[k++].alpha = (fsy2 - sy2) * scale;
    }
  }

  // resize each column of each color channel
  bzero(dst, chan*width*dheight*sizeof(double));
  for (int c = 0; c < chan; c++) {
    for (int x = 0; x < width; x++) {
      double *s = src + c*width*sheight + x*sheight;
      double *d = dst + c*width*dheight + x;
      alphacopy(s, d, ofs, k);
    }
  }
}

// main function
// takes a double color image and a scaling factor
// returns resized image
mxArray *resize(const mxArray *mxsrc, const mxArray *mxscale) {
  double *src = (double *)mxGetPr(mxsrc);
  const int *sdims = mxGetDimensions(mxsrc);
  if (mxGetNumberOfDimensions(mxsrc) != 3 ||
      mxGetClassID(mxsrc) != mxDOUBLE_CLASS)
    mexErrMsgTxt("Invalid input");

  double scale = mxGetScalar(mxscale);
  if (scale > 1)
    mexErrMsgTxt("Invalid scaling factor");

  int ddims[3];
  ddims[0] = (int)round(sdims[0]*scale);
  ddims[1] = (int)round(sdims[1]*scale);
  ddims[2] = sdims[2];
  mxArray *mxdst = mxCreateNumericArray(3, ddims, mxDOUBLE_CLASS, mxREAL);
  double *dst = (double *)mxGetPr(mxdst);

  double *tmp = (double *)mxCalloc(ddims[0]*sdims[1]*sdims[2], sizeof(double));
  resize1dtran(src, sdims[0], tmp, ddims[0], sdims[1], sdims[2]);
  resize1dtran(tmp, sdims[1], dst, ddims[1], ddims[0], sdims[2]);
  mxFree(tmp);

  return mxdst;
}

// matlab entry point
// dst = resize(src, scale)
// image should be color with double values
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  if (nrhs != 2)
    mexErrMsgTxt("Wrong number of inputs");
  if (nlhs != 1)
    mexErrMsgTxt("Wrong number of outputs");
  plhs[0] = resize(prhs[0], prhs[1]);
}
Posted
Updated 12-Dec-13 22:34pm
v4
Comments
OriginalGriff 13-Dec-13 4:25am    
Don't paste links - it looks like you are too lazy to care about helping us to help you.
Post the relevant code fragments directly instead, so we can see it all together.
Remember, the easier you make it for us to look at your problem (without wading through loads of irrelevant rubbish) the quicker you generally get a response - and a better response as well..
Use the "Improve question" widget to edit your question and provide better information.
OriginalGriff 13-Dec-13 4:52am    
When I said "relevant code fragments", I didn't mean the whole file! :laugh:
Just the line that is giving you the problem (line 36) and a couple of lines either side for context. And mark the line so we can find it easily! The rest of the code is what I described as "loads of irrelevant rubbish" that we have to wade through to find the actual bit with the problem! And tell us what the compiler is saying is wrong with it...

Counting the lines manually, and guessing as to the error message:
You forgot the word "struct":
C++
int len = (int)ceil(dheight*invscale) + 2*dheight;
alphainfo ofs[len];
int k = 0;
Becomes
C++
int len = (int)ceil(dheight*invscale) + 2*dheight;
struct alphainfo ofs[len];
int k = 0;
But it's also possible it's complaining that len needs to be a constant value.
 
Share this answer
 
Comments
goldpower 13-Dec-13 5:08am    
@OriginalGriff8
not work !!
OriginalGriff 13-Dec-13 5:19am    
See what I mean?
If you give us actual relevant information, we can target what the problem is.
"not work!!" (apart from being rude) is not at all helpful. It tells us nothing about why it doesn't work! Any chance of an error message this week?
goldpower 13-Dec-13 5:20am    
i edit resize.cc but Unable to complete successfully.

mex -O -largeArrayDims resize.cc
resize.cc
resize.cc(36) : error C2057: expected constant expression
resize.cc(36) : error C2466: cannot allocate an array of constant size 0
resize.cc(36) : error C2133: 'ofs' : unknown size
resize.cc(70) : error C3861: 'bzero': identifier not found
resize.cc(85) : error C2440: 'initializing' : cannot convert from 'const mwSize *' to 'const int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
resize.cc(95) : error C3861: 'round': identifier not found
resize.cc(96) : error C3861: 'round': identifier not found
resize.cc(98) : error C2664: 'mxCreateNumericArray_730' : cannot convert parameter 2 from 'int [3]' to 'const mwSize *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

D:\PROGRA~2\MATLAB\R2013A\BIN\MEX.PL: Error: Compile of 'resize.cc' failed.

Error using mex (line 206)
Unable to complete successfully.
OriginalGriff 13-Dec-13 5:33am    
There is a small clue there:
"expected constant expression"
If you look back at what I said above:
"it's also possible it's complaining that len needs to be a constant value"
You can't allocate an array of dynamic size like that: it has to have a constant value like 6, or 1024 or similar. Variables won't work.

You need to use mxMalloc instead:
http://www.mathworks.co.uk/help/matlab/apiref/mxmalloc.html
i'm edited resize.cc:

add line 5:
C++
static inline double round(double x) { return (floor(x + 0.5)); } 


edit line 36 :
C++
struct alphainfo* ofs = (struct alphainfo*)malloc(len * sizeof(alphainfo)); 


edit line 71:
C++
memset(dst,0, chan*width*dheight*sizeof(double));



>> mex -O resize.cc 

complete successfully. (created resize.mexw64)

.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900