User Tools

Site Tools


installation_guide:gdaloncygwin

How to build GDAL on CYGWIN x64?

To install CYGWIN on windows follow this guide and also ensure that; (1) the latest GCC is installed, (2) wget and cmake are also installed. To have a quick check of which packages are installed just type the following in a Cygwin command prompt:

cygcheck -c -d

After the Cygwin installer completes, it’s very important to keep the installer around. The installer is an executable named either setup-x86.exe or setup-x86_64.exe, and you’ll need it to add or remove Cygwin packages in the future. I suggest moving the installer to the same folder where you installed Cygwin itself; typically C:\cygwin or C:\cygwin64.

Now let's install the GDAL source code.

  • Step 0: Open a Cygwin terminal and go to /home directory
  • Step 1: Search the web for the last gdal source code
  • Step 2: Download the source file at download folder with wget “link to gdal source code”
wget http://download.osgeo.org/gdal/1.11.2/gdal-1.11.2.tar.gz
  • Step 3: Run the ./configure command to check some details about the machine on which the software is going to be installed and create a Makefile. When you run the configure script you would see a lot of output on the screen , each being some sort of question and a respective yes/no as the reply. If any of the major requirements are missing on your system, the configure script would exit and you cannot proceed with the installation, until you get those required things. For a lighter build up (i.e. without -libtool) type
./configure --prefix=$HOME --with-libz=internal --with-python=no --with-jasper=no --with-threads=yes --without-libtool --enable-fast-install
  • Step 4: If you get no errors and the configure script runs successfully (if there is any error the last few lines of the output would glaringly be stating the error, otherwise here is an example of a successful config.status report) then you can proceed with the next command which is make. Basically the make utility compiles all your program code and creates the executables.
  • Step 5: If make ran successfully then you are almost done with the installation. Only the last step remains which is “make install”. The install section happens to be only a part where the executables and other required files created during the last step (i.e. make) are copied into the required final directories on your machine. E.g. the executable that the user runs may be copied to the /usr/local/bin so that all users are able to run the software. Similarly all the other files are also copied to the standard directories in Linux. Remember that when you ran make, all the executables were created in the temporary directory where you had unzipped your original tarball. So when you run make install, these executables are copied to the final directories.
  • Step 6: OK, if you got GDAL installed locally then here is what you must do to set up your environment to recognise these local libraries, so that you can link to them. Add the path to the gdal include files and lib into your .bashrc file. Open the .bashrc file with a text editor and add;
export PATH=$PATH:$HOME/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/local/lib:$HOME/lib
export MANPATH=$MANPATH:$HOME/man

Log out and log back in again

Check that the paths have changed:

echo $LD_LIBRARY_PATH

You should get something /usr/lib:/usr/local/lib:/ouce-home/staff/cenv0222/lib but with your username, of course.

Test that GDAL is properly installed

Lets test if GDAL is now properly installed under Cygwinx64. Copy the following C++ script into a file named gdal_test.cpp and save it into a folder within our home directory i.e. /home/GDALTest/gdal_test.cpp. This script just load GDAL drivers and inform us when is done.

#include <iostream>
using namespace std;
#include "gdal_priv.h"
int main ()
{
  cout << "Started...\n";
  // Register all available GDAL drivers
  GDALAllRegister();
  cout << "GDAL drivers loaded\n";
  return 0;
}

From a Cygwin terminal go to the folder where gdal_test.cpp is located and just type g++ gdal_test.cpp -o gdal_test. I got this error message back:

/tmp/ccGpf0Oa.o: In function `main':
gdal_test.cpp:(.text+0x14): undefined reference to `GDALAllRegister'
collect2: error: ld returned 1 exit status

which means that the thing compiled OK, but the linker (ld) couldn't find the GDAL library to link it in with our test program. Which is not surprising, we have to specify the location of the GDAL libraries.

GDAL provides a tool called gdal-config to do this.

So we run:

gdal-config

I got this output:

Usage: gdal-config [OPTIONS]
Options:
        [--prefix[=DIR]]
        [--libs]
        [--dep-libs]
        [--cflags]
        [--datadir]
        [--version]
        [--ogr-enabled]
        [--formats]

We want it to tell us where the libs are, so we run:

gdal-config --libs

I got this output:

$ -L/usr/lib64 -lgdal

which is the location of the GDAL libraries on my laptop (you will probably get something different). This output is ready-formatted for the g++ compiler, which is convenient. So now we run:

g++ gdal_test.cpp -L/usr/lib64 -lgdal -o gdal_test

and the program should build with no error messages. Check that the executable file gdal_test is there, then run it.

./gdal_test

You should get this output:

Started...
GDAL drivers loaded

If you compile but get a missing libgdal.dll you might need to install the shared and static libraries manually:

cp libgdal.dll ../../home/bin/
cp libgdal.a ../../home/lib/

Try to run again ./gdal_test and this should do the trick.

Check-lib failed

I have came accroos the error below error message when creating the executables by the make utility.

/home/apg1e14/GDAL/gdal-1.11.2/frmts/o/.libs/dgif_lib.o: In function `DGifOpenFileHandle':
/home/apg1e14/GDAL/gdal-1.11.2/frmts/gif/giflib/dgif_lib.c:111: undefined reference to `setmode'
/home/apg1e14/GDAL/gdal-1.11.2/frmts/gif/giflib/dgif_lib.c:111:(.text+0x8e1): relocation truncated to fit:     R_X86_64_PC32 against undefined symbol `setmode'
/home/apg1e14/GDAL/gdal-1.11.2/frmts/o/.libs/egif_lib.o: In function `EGifOpenFileHandle':
/home/apg1e14/GDAL/gdal-1.11.2/frmts/gif/giflib/egif_lib.c:137: undefined reference to `setmode'
/home/apg1e14/GDAL/gdal-1.11.2/frmts/gif/giflib/egif_lib.c:137:(.text+0x4c7): relocation truncated to fit:   R_X86_64_PC32 against undefined symbol `setmode'
collect2: error: ld returned 1 exit status
GNUmakefile:41: recipe for target 'libgdal.la' failed
make[1]: *** [libgdal.la] Error 1
make[1]: Leaving directory '/home/apg1e14/GDAL/gdal-1.11.2'
GNUmakefile:50: recipe for target 'check-lib' failed
make: *** [check-lib] Error 2

If this happen to you, it is recommended that you run make clean which deletes all the already compiled object files. If you google this error you will find plenty of causes and solutions. I solved just by run the Cygwin installer to reinstall/update all packages (takes quite a long time but ensures that I was not missing any important package).

installation_guide/gdaloncygwin.txt · Last modified: 2016/03/20 19:13 by coastalmeadmin