[Gdal-dev] Trouble linking GDAL library and Matlab
Joaquim Luis
jluis at ualg.pt
Fri May 4 13:24:58 EDT 2007
guillaume huby wrote:
> Hello,
>
> Matlab offers the possibility to compile C programs and use them as
> matlab functions. This is called Mex files and works almost like
> making a dll. I used Visual Studio 2005 Pro and FWTools 1.2.1 in order
> to be able to use GDAL inside Matlab.
>
> The simple C program I made is below and just take a string in input
> and returns 1.
Guillaume,
Why do you include gdal_priv.h?
In my mexs I always include only gdal.h.
In case you are interested my package, Mirone, has a gdalread and a
gdalwrite mex file.
I also have a gdalwarp mex but it is not released yet. It is waiting for
bug 1393
http://trac.osgeo.org/gdal/ticket/1393
to be corrected
Mirone is here
w3.ualg.pt/~jluis/mirone
Joaquim Luis
>
> ---------------------------------Start
> Code-----------------------------------------
> #include "gdal_priv.h"
> #include "mex.h"
>
> void mexFunction(int nlhs, mxArray *plhs[],
> int nrhs, const mxArray *prhs[])
> {
>
> double *y;
> char *pszFilename;
> int bufLen;
> int status;
>
> /* Create a 1-by-1 matrix for the return argument. */
> plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
>
> /* Input must be a string. */
> if (mxIsChar(prhs[0]) != 1)
> mexErrMsgTxt("Input must be a string.");
>
> /* Input must be a row vector. */
> if (mxGetM(prhs[0]) != 1)
> mexErrMsgTxt("Input must be a row vector");
>
> /* Get the length of the input string. */
> bufLen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
>
> /* Allocate memory for input string. */
> pszFilename = (char *) mxCalloc(bufLen, sizeof(char));
>
> /* Copy string data from prhs[0] into a C string inputBuf. */
> status = mxGetString(prhs[0], pszFilename, bufLen);
> if (status != 0)
> mexWarnMsgTxt("Not enough space. String is truncated.");
>
> /*GDALDataset *poDataset;
>
> GDALAllRegister();*/
>
> /*poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
> if( poDataset == NULL ) {
> } else {
> mexWarnMsgTxt("Could not open dataset.");
> }*/
>
> /* Assign a pointer to the output. */
> y = mxGetPr(plhs[0]);
>
> *y = 1.0 ;
> }
> --------------------------------------------End
> Code-------------------------------------
>
> Without #include "gdal_priv.h" everything is fine, but with there is a
> problem of dependency (Matlab cannot find some library) althought all
> gdal (all found in FWTools\bin) dlls are in path (checked with depends
> walker).
> Discussion with Matlab support identified the problem in "gdal_priv.h"
> line 56 #include <vector>. AFAIK, <vector> is a STL standard C++ library.
> Did I missed something ? linking with some special library ?
>
> Thanks for your help.
> Guillaume.
> ------------------------------------------------------------------------
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
More information about the Gdal-dev
mailing list