Hello,<br><br>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.
<br><br>The simple C program I made is below and just take a string in input and returns 1.<br><br>---------------------------------Start Code-----------------------------------------<br>#include &quot;gdal_priv.h&quot;<br>
#include &quot;mex.h&quot;<br><br>void mexFunction(int nlhs, mxArray *plhs[],<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;int nrhs, const mxArray *prhs[])<br>{<br><br>&nbsp;&nbsp;&nbsp; double *y;<br>&nbsp;&nbsp;&nbsp; char *pszFilename;<br>&nbsp;&nbsp;&nbsp; int bufLen;<br>&nbsp;&nbsp;&nbsp; int status;
<br><br>&nbsp;&nbsp;&nbsp; /* Create a 1-by-1 matrix for the return argument. */<br>&nbsp;&nbsp;&nbsp; plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);<br><br>&nbsp;&nbsp;&nbsp; /* Input must be a string. */<br>&nbsp;&nbsp;&nbsp; if (mxIsChar(prhs[0]) != 1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mexErrMsgTxt(&quot;Input must be a string.&quot;);
<br><br>&nbsp;&nbsp;&nbsp; /* Input must be a row vector. */<br>&nbsp;&nbsp;&nbsp; if (mxGetM(prhs[0]) != 1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mexErrMsgTxt(&quot;Input must be a row vector&quot;);<br><br>&nbsp;&nbsp;&nbsp; /* Get the length of the input string. */<br>&nbsp;&nbsp;&nbsp; bufLen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
<br><br>&nbsp;&nbsp;&nbsp; /* Allocate memory for input string. */<br>&nbsp;&nbsp;&nbsp; pszFilename = (char *) mxCalloc(bufLen, sizeof(char));<br><br>&nbsp;&nbsp;&nbsp; /* Copy string data from prhs[0] into a C string inputBuf. */<br>&nbsp;&nbsp;&nbsp; status = mxGetString(prhs[0], pszFilename, bufLen);
<br>&nbsp;&nbsp;&nbsp; if (status != 0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mexWarnMsgTxt(&quot;Not enough space. String is truncated.&quot;);<br><br>&nbsp;&nbsp;&nbsp; /*GDALDataset&nbsp; *poDataset;<br><br>&nbsp;&nbsp;&nbsp; GDALAllRegister();*/<br><br>&nbsp;&nbsp;&nbsp; /*poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
<br>&nbsp;&nbsp;&nbsp; if( poDataset == NULL ) {<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; mexWarnMsgTxt(&quot;Could not open dataset.&quot;);<br>&nbsp;&nbsp;&nbsp; }*/<br><br>&nbsp;&nbsp;&nbsp; /* Assign a pointer to the output. */<br>&nbsp;&nbsp;&nbsp; y = mxGetPr(plhs[0]);<br><br>&nbsp;&nbsp;&nbsp; *y = 1.0
;<br>}<br>--------------------------------------------End Code-------------------------------------<br><br>Without #include &quot;gdal_priv.h&quot; 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).
<br>Discussion with Matlab support identified the problem in &quot;gdal_priv.h&quot; line 56 #include &lt;vector&gt;. AFAIK, &lt;vector&gt; is a STL standard C++ library.<br>Did I missed something ? linking with some special library ?
<br><br>Thanks for your help.<br>Guillaume.<br>