[gdal-dev] Stack Overflow in gdal with HDF5 using VC2008

Mateusz Loskot mateusz at loskot.net
Tue Aug 11 21:17:32 EDT 2009


atubar wrote:
> I am sorry for that I can not take a test in VC++ 2005, because I
> built every essential dll in VC++ 2008, and I now only install VC2008
> on my computer. Will it take any different results if  dlls built
> with different compiler ?

Of course there may be. For instance, linker may not accept it
and abort with errors. But looks like you're using VS2008 now,
so just rebuild all the libraries and client program
using this compiler.

> I simply have a check in local : One with
> pre-built dlls from HDFGroup ,such as zlib, szip, jpeg.

Ensure you downloaded HDF libraries for VS2008.

> And the
> other with all dlls built from source. But When reading a hdf5 file,
> they all gave me a report about  Stack Overflow.

What is the exact and the complete error message.

> The HDF5 file is a
> sample data contained in hdfview which provided by HDFGroup and can
> be found in its website. And the code I write is below: 
>
//////////////////////////////////////////////////////////////////////////////////////
> #include <iostream>
> using namespace std;

Open the namespace *after* all headers are include, not before.

> #include "gdal_priv.h"
> #pragma comment(lib,"gdal_i.lib")

using namespace std;

> int main()
> {
>  GDALAllRegister();
>  char* filename="D:\\Documents and Settings\\Visual Studio
2008\\Projects\\GdalConsole\\Debug\\hdf5_test.h5";

const char* not char*

>  char *pszFormat="HDF5";

const char*

>  GDALDriver *poDriver =
GetGDALDriverManager()->GetDriverByName(pszFormat);
> ////////////// here poDriver is non-null pointer////////////
>  if( poDriver != NULL )
>  {
>   ........................
>  }
>  else
>  {
>   cout<<"Gdal do not support HDF4!"<<endl;

likely, return 0; is missing from logical point.

>  }
>  GDALDataset *poDataset;
>  poDataset= (GDALDataset *) GDALOpen( filename, GA_ReadOnly);
> /////////////////when code run here, it reports that stack overflow
>  if(poDataset == NULL)
>  {
>   cout<<"error!";
>   return 0;
>  }
>  else
>  {
>   ...................
>  }
>  poDataset=NULL;

This is not how you are supposed to close GDAL dataset.

Pleasse, (re)read "Closing the Dataset" section here:

http://gdal.org/gdal_tutorial.html

>  return 0;
> }
>
/////////////////////////////////////////////////////////////////////////////

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org


More information about the gdal-dev mailing list