[Gdal-dev] Trouble linking GDAL library and Matlab
guillaume huby
guillaume.huby.lists at gmail.com
Fri May 4 05:12:40 EDT 2007
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.
---------------------------------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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20070504/78b6b736/attachment.html
More information about the Gdal-dev
mailing list