[Gdal-dev] Re: MinGW & GDAL: "[Linker error] undefined reference..."

Chapman, Martin MChapman at sanz.com
Thu May 27 23:22:52 EDT 2004


Try this:
 
#include <iostream>
#include "gdal_priv.h"
 
int nRasterX = 0, nRasterY = 0, nNumberOfBands = 0;
string sFileName = "c:\\somefile.tif";
 
GDALAllRegister();
GDALDataset* pDataset = (GDALDataset*) GDALOpen(sFileName.c_str(), GA_ReadOnly);
 
if ( pDataset == NULL )
{
 cout << (char*) CPLGetLastErrorMsg() << endl;
 return false;
}
 
nNumberOfBands = pDataset->GetRasterCount();
cout << "Num Bands: " << nNumberOfBands << endl;
 
if (nNumberOfBands > 0)
{
 nRasterX = pDataset->GetRasterBand(1)->GetXSize();
 nRasterY = pDataset->GetRasterBand(1)->GetYSize();
 cout << "RasterX: " << nRasterX << "\nnRasterY: " << nRasterY << endl;
}
 
if (pDataset)
 GDALClose(pDataset);
 
I just cut and pasted some code, so it might need a couple of tweaks.  Send me what the output is from this code.  What platform are you running this on?  If it's visual studio on windows you need to link the gdal_i.lib in your project settings.  If you are using Linux it needs to be linked in the make file. 
 
Martin
 
 

	-----Original Message----- 
	From: J.Krueger [mailto:kruegerj at gmx.de] 
	Sent: Mon 7/26/2004 7:13 PM 
	To: gdal-dev at remotesensing.org 
	Cc: 
	Subject: [Gdal-dev] Re: MinGW & GDAL: "[Linker error] undefined reference..."
	
	

	Ok, I thought I had managed it, but while I can open files now, I am now
	getting this damn error again - only this time not for all gdal
	instructions. For example I can open/close datasets, but I can't query
	them for certain (any?) information:
	
	-cut-
	   Dataset1 = (GDALDataset *) GDALOpen( filename1, GA_ReadOnly );
	   int xsizefile1 = Dataset1->GetRasterXSize();
	   int ysizefile1 = Dataset1->GetRasterYSize();
	-cut-
	
	results in the following error messages:
	[Linker error] undefined reference to `GDALDataset::GetRasterXSize()'
	[Linker error] undefined reference to `GDALDataset::GetRasterYSize()'
	
	The mere opening of the Dataset does not cause any problems. As soon as
	I uncomment the GetRasterXSize/GetRasterYSize instructions the program
	compiles properly and the Image files can be accessed.
	
	Any ideas? Do I have to add something more to my compiler/linker
	switches, or is it just a problem with the code? If I'm still missing a
	switch: where can I find some detailed info/documentation on what is
	needed, so I don't have to ask here every time?
	
	_______________________________________________
	Gdal-dev mailing list
	Gdal-dev at remotesensing.org
	http://remotesensing.org/mailman/listinfo/gdal-dev
	

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 6770 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20040527/7702014a/attachment.bin


More information about the Gdal-dev mailing list