[Gdal-dev] how to link gdal to my programs?

Andrew Finley afinley at gis.umn.edu
Tue Jan 13 17:49:34 EST 2004


Hi Pushkar,
Assuming that your ld.so.conf file has the correct path to the gdal
lib, and you have run ldconfig you should be able to link the lib
like this:

g++ /usr/local/lib/libgdal.1.1.so something.cpp

Your include in something.cpp might be:

#include "/usr/local/include/gdal_priv.h"
#include "/usr/local/include/ogr_spatialref.h"

hope this helps
-andy

On Tue, 2004-01-13 at 16:19, Pushkar Pradhan wrote:
> I'm having a little trouble linking gdal libs. to my C++ code.
> These are the compile errors:
> Redstone[1234] pushkar$ g++ -g -o main
> dwt-serial.cpp -Ierrs/ -Imisc/ -Iip/ -I../gdal-1.1.9/include/
> dwt-serial.cpp: In function `int main(int, char **)':
> dwt-serial.cpp:20: `GDALDataset' undeclared (first use this function)
> dwt-serial.cpp:20: (Each undeclared identifier is reported only once
> dwt-serial.cpp:20: for each function it appears in.)
> dwt-serial.cpp:20: `poDataset' undeclared (first use this function)
> dwt-serial.cpp:26: parse error before `)'
> 
> I tried -lgdal.1.1, -lgdal.1.1.9 but neither worked. I've set the path to
> GDAL (/rstc/user1/erc/pushkar/gdal-1.1.9/lib) in my $LD_LIBRARY_PATH
> 
> Here's my first code:
> #include <gdal.h>
> <--other includes-->
> int main(int argc, char **argv)
> {
>   char *inFile;
>   char *dwtFile;
> 
>   GDALDataset *poDataset;
> 
>   GDALAllRegister();
> 
>   inFile = argv[1];
> 
>   poDataset = (GDALDataset *) GDALOpen(inFile, GA_ReadOnly);
>   if(poDataset == NULL)
>     exit(EXIT_FAILURE);
> }
> 
> Sorry if it was on the gdal homepage and I missed it. Can somebody help.
> Thanks
> Pushkar
> 
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at remotesensing.org
> http://remotesensing.org/mailman/listinfo/gdal-dev
-- 
Andrew Finley, Research Fellow
Department of Forest Resources
College of Natural Resources           
University of Minnesota
305 Green Hall
1530 Cleveland Avenue N.
St. Paul, MN 55108

Ph 612-624-1714 office
www.cnr.umn.edu/FR/people/facstaff/finley/index.html



More information about the Gdal-dev mailing list