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

J.Krueger kruegerj at gmx.de
Tue Jul 27 13:53:10 EDT 2004


Chapman, Martin wrote:
> Try this:
[...]
> 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. 

-cut-
Compiler: Default compiler
Executing  mingw32-g++.exe...
mingw32-g++.exe "C:\Dev-Cpp\clessons\sigma\test.cpp" -o 
"C:\Dev-Cpp\clessons\sigma\test.exe"   -fexpensive-optimizations -O2 
-I"C:\Dev-Cpp\include\c++"  -I"C:\Dev-Cpp\include\c++\mingw32" 
-I"C:\Dev-Cpp\include\c++\backward" 
-I"C:\Dev-Cpp\lib\gcc-lib\mingw32\3.2\include"  -I"C:\Dev-Cpp\include" 
-I"C:\Dev-Cpp\gdal\include"   -L"C:\Dev-Cpp\lib" -L"C:\Dev-Cpp\gdal\lib" 
-Lc:/dev-cpp/gdal/bin -lgdal12
C:\DOKUME~1\JOCHEN~1.GOG\LOKALE~1\Temp/ccMXbaaa.o(.text+0x6b):test.cpp: 
undefined reference to `GDALDataset::GetRasterCount()'

C:\DOKUME~1\JOCHEN~1.GOG\LOKALE~1\Temp/ccMXbaaa.o(.text+0xe8):test.cpp: 
undefined reference to `GDALDataset::GetRasterBand(int)'
C:\DOKUME~1\JOCHEN~1.GOG\LOKALE~1\Temp/ccMXbaaa.o(.text+0xf0):test.cpp: 
undefined reference to `GDALRasterBand::GetXSize()'
C:\DOKUME~1\JOCHEN~1.GOG\LOKALE~1\Temp/ccMXbaaa.o(.text+0xff):test.cpp: 
undefined reference to `GDALDataset::GetRasterBand(int)'
C:\DOKUME~1\JOCHEN~1.GOG\LOKALE~1\Temp/ccMXbaaa.o(.text+0x107):test.cpp: 
undefined reference to `GDALRasterBand::GetYSize()'

Execution terminated
-cut-

it's the same problem. I can use the gdal functions to open the 
datafiles, but as soon as there's any instructions that to query 
information from inside the dataset I can't link the binary anymore.

Btw: I'm using gcc (Dev-C++ IDE with MinGW) to compile the file. And I 
already have the library in the linker's command line (else I'd get the 
same errors for the

Here's the comple function that's giving me the headaches:

-cut-
int evaluate_Inputfiles(char* infile1, char* infile2) {
   GDALAllRegister();
   // Can the files be opened at all?
   int check=0;
   check=evaluate_Inputfile(infile1);
   if (check) return 1;
   check=evaluate_Inputfile(infile2);
   if (check) return 1;
   // Do they have the same size?
   const char* filename1=infile1;
   const char* filename2=infile2;
   highresDataset = (GDALDataset *) GDALOpen( filename1, GA_ReadOnly );
   rastersizex = (highresDataset.GetRasterXSize());
   rastersizey = (highresDataset.GetRasterYSize());
   int xsize1 = rastersizex;
   int ysize1 = rastersizey;
   lowresDataset = (GDALDataset *) GDALOpen( filename2, GA_ReadOnly );
   rastersizex = (lowresDataset->GetRasterXSize());
   rastersizey = (lowresDataset->GetRasterYSize());
   int xsize2 = rastersizex;
   int ysize2 = rastersizey;
   if ((xsize1 != xsize2) || (ysize1 != ysize2)) {
       cout << endl << "Die beiden Inputfiles sind verschieden groß!" << 
endl;
       return 1;
   };
   return 0;
}
-cut-

The function 'evaluate_inputfile' simply tries to open the datafiles. 
That function's working fine, as is the whole as soon as I unmark the 
parts where I try to get the size of the files:

   rastersizex = (lowresDataset->GetRasterXSize());
   rastersizey = (lowresDataset->GetRasterYSize());

Without these lines the function (and the rest of the code) compiles 
fine. Same with your code - as soon as all parts that actually query 
information from within the dataset are remove it compiles fine...



More information about the Gdal-dev mailing list