[GIS] Set up GDAL for C++ in RHEL

cgdal

I've got GDAL installed from the latest 1.11.2 source, but when I try to make by C++ executable I get undefined references to "GDALAllRegister" and basically all the GDAL functions I call. The same cpp file compiles fine on my Mac, but I can't seem to get the include directories correct.

In my CMakeLists.txt I have:

find_package( GDAL )
include_directories( ${GDAL_INCLUDE_DIRS} )

And I've made sure GDAL_INCLUDE_DIRS points to /usr/local/lib where the gdal libraries are located.

Best Answer

As requested,

You need to set the include directory properly:

GDAL_INCLUDE_DIR=/usr/local/include

include_directories( ${GDAL_INCLUDE_DIR} )

on a normal from source build. Some packages install the headers in ${PREFIX}/gdal (e.g. /usr/local/include/gdal), but the build from source does not. Then you have to also link to the gdal library:

target_link_libraries( your_target ${GDAL_LIBRARY} )