Version 6 (modified by ilucena, 16 years ago) ( diff )


FAQ - Installation and Building

  1. Where can I find development version of GDAL?
  2. Can I get a MS Visual Studio Project file for GDAL?
  3. Can I build GDAL with MS Visual C++ 2005 Express Edition?
  4. Can I build GDAL with Cygwin or MinGW?
  5. Can I build GDAL with Borland C or other C compilers?
  6. Why Visual C++ 8.0 fails with C2894 error in wspiapi.h when building GDAL with libcurl support?

Where can I find development version of GDAL?

You can checkout it directly from SVN repository. Visit Downloading GDAL/OGR Source Wiki page for detailed instructions.

Can I get a MS Visual Studio Project file for GDAL?

The GDAL developers find it more convenient to build with makefiles and the Visual Studio NMAKE utility. Maintaining a parallel set of project files for GDAL is too much work, so there are no full project files directly available from the maintainers.

There are very simple project files available since GDAL/OGR 1.4.0 that just invoke the makefiles for building, but make debugging somewhat more convenient. These are the makegdal71.vcproj and makegdal80.vcproj files in the GDAL root directory. See Using Makefile Projects for details.

Occasionally other users do prepare full project files, and you may be able to get them by asking on the gdal-dev list. However, I would strongly suggest you just use the NMAKE based build system. With debugging enabled you can still debug into GDAL with Visual Studio.

Can I build GDAL with MS Visual C++ 2005 Express Edition?

Yes, you can. It's also possible to use GDAL libraries in applications developed using Microsoft Visual C++ 2005 Express Edition.

  • Download and install Microsoft Platform SDK. Also, follow these instructions carefully without omitting any of steps presented there:
  • Add following two paths to Include files in the Visual C++ IDE settings. Do it the same way as presented in Step 3 from the website above.
C:\\Program Files\\Microsoft Platform SDK\\Include\\atl
C:\\Program Files\\Microsoft Platform SDK\\Include\\mfc
  • Since you will build GDAL from command line using nmake tool, you also need to set or update INCLUDE and LIB environment variables manually. You can do it in two ways:
    1. using the System applet available in the Control Panel
    2. by editing vsvars32.bat script located in
      C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat

These variables should have following values assigned:

INCLUDE=C:\\Program Files\\Microsoft Visual Studio 8\\VC\\Include;
        C:\\Program Files\\Microsoft Platform SDK\\Include;
        C:\\Program Files\\Microsoft Platform SDK\\Include\\mfc;
        C:\\Program Files\\Microsoft Platform SDK\\Include\\atl;%INCLUDE%

LIB=C:\\Program Files\\Microsoft Visual Studio 8\\VC\\Lib;
    C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\lib;
    C:\\Program Files\\Microsoft Platform SDK\\lib;%LIB%

NOTE: If you have edited system-wide INCLUDE and LIB variables, using System applet, every Console (cmd.exe) will have it properly set. But if you have edited them through vsvars32.bat script, you will need to run this script in the Console before every compilation.

  • Patch atlwin.h header

At line 1725 add int i; declaration, so it looks as follows:

BOOL SetChainEntry(DWORD dwChainID, CMessageMap* pObject, DWORD dwMsgMapID = 0)
    int i;
    // first search for an existing entry

    for(i = 0; i < m_aChainEntry.GetSize(); i++)
  • Patch atlbase.h header

At line 287, comment AllocStdCallThunk and FreeStdCallThunk functions and add macros replacements:

PVOID __stdcall __AllocStdCallThunk(VOID);
VOID __stdcall __FreeStdCallThunk(PVOID);

#define AllocStdCallThunk() __AllocStdCallThunk()
#define FreeStdCallThunk(p) __FreeStdCallThunk(p)

#pragma comment(lib, "atlthunk.lib")

#define AllocStdCallThunk() HeapAlloc(GetProcessHeap(),0,sizeof(_stdcallthunk))
#define FreeStdCallThunk(p) HeapFree(GetProcessHeap(), 0, p)
  • Building GDAL
    • Open console windows (Start -> Run -> cmd.exe -> OK)
    • If you have edited vsvars32.bat script, you need to run it using full path:
      C:\> "C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\Tools\\vsvars32.bat"
      Setting environment for using Microsoft Visual Studio 2005 x86 tools
    • Go do GDAL sources root directory, for example:
      C:\> cd work\gdal
    • Run nmake to compile
      C:\work\gdal> nmake /f
    • If no errors occur, after a few minutes you should see GDAL libraries in C:\work\gdal.

Now, you can use these libraries in your applications developed using Visual C++ 2005 Express Edition.

Can I build GDAL with Cygwin or MinGW?

GDAL should build with Cygwin using the Unix-like style build methodology. It is also possible to build with MinGW and MSYS though there might be complications. The following might work:

./configure --prefix=$PATH_TO_MINGW_ROOT --host=mingw32 \
	--without-libtool --without-python $YOUR_CONFIG_OPTIONS

Using external win32 libraries will often be problematic with either of these environments - at the least requiring some manual hacking of the GDALmake.opt file.

Howto compile the (NG) Python bindings:

cd swig\python
python build -c mingw32
cp build\lib.win32-2.5\* c:\python25\lib\site-packages\

(some details may need adjusting)

Howto compile the Perl bindings:

cd swig\perl
perl Makefile.PL
make.bat install

(the perl may need to be compiled with MinGW)

If you have swig, the bindings can be regenerated in MSYS prompt by command "make generate".

Can I build GDAL with Borland C or other C compilers?

These are not supported compilers for GDAL; however, GDAL is mostly pretty generic, so if you are willing to take on the onerous task of building an appropriate makefile / project file it should be possible. You will find most portability issues in the gdal/port/cpl_port.h file and you will need to prepare a gdal/port/cpl_config.h file appropriate to your platform. Using as a guide may be useful.

Why Visual C++ 8.0 fails with C2894 error in wspiapi.h when building GDAL with libcurl support?

Here is the complete error message of this issue:

C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\wspiapi.h(44) : 
   error C2894: templates cannot be declared to have 'C' linkage

This is a known bug in the wspiapi.h header. One of possible solutions is to manually patch curl.h replacing lines 153 - 154

#include <winsock2.h>
#include <ws2tcpip.h>

with the following code:

#ifdef __cplusplus
#include <winsock2.h>
#include <ws2tcpip.h>
#ifdef __cplusplus
extern "C" {

This problem occurs in libcurl <= 7.17.1. Perhaps, later versions of libcurl will include this fix.

Note: See TracWiki for help on using the wiki.