wiki:FAQInstallationAndBuilding

Version 14 (modified by Mateusz Łoskot, 15 years ago) ( diff )

Q: What is GDAL_DATA environment variable?

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++ 2008 Express Edition?
  4. Can I build GDAL with MS Visual C++ 2005 Express Edition?
  5. Can I build GDAL with Cygwin or MinGW?
  6. Can I build GDAL with Borland C or other C compilers?
  7. Why Visual C++ 8.0 fails with C2894 error in wspiapi.h when building GDAL with libcurl support?
  8. How can i add particular LDFLAGS with GDAL < 1.5
  9. I am having problem building with external libraries, where can I look?
  10. What is GDAL_DATA environment variable?
  11. How to set GDAL_DATA variable?

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++ 2008 Express Edition?

Yes, since at least GDAL/OGR 1.5 this should be straight forward. Before proceeding with the normal NMAKE based build just ensure that the MSVC_VER macro near the top of gdal/nmake.opt is changed to 1500 to reflect the compiler version (Visual C++ 9.0). This will modify the build to skip the VB6 interfaces which depend on ATL components not available in the express edition.

Microsoft Express Edition Downloads

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")
***************************************************/

/* NEW MACROS */
#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 to GDAL sources root directory, for example:
      C:\> cd work\gdal
      
    • Run nmake to compile
      C:\work\gdal> nmake /f makefile.vc
      
    • 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 setup.py 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
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 cpl_config.h.vc 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
}
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#ifdef __cplusplus
extern "C" {
#endif

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

How can i add particular LDFLAGS with GDAL < 1.5

export the LNK_FLAGS variable with your habitual LDFLAGS content

export LNK_FLAGS=-Wl,-rpath=/foo/lib -l/foo/lib

I am having problem building with external libraries, where can I look?

There are additional hints and suggestions for building GDAL with various external support libraries in the BuildHints topic.

What is GDAL_DATA environment variable?

GDAL_DATA is an environment variable used to specify location of supporting files used by GDAL library as well as GDAL and OGR utilities. For instance, in order for OGR and GDAL to properly evaluate EPSG codes you need to have the EPSG support files (so called dictionaries, mostly in CSV format), like gcs.csv and pcs.csv, found in the directory pointed by GDAL_DATA variable.

How to set GDAL_DATA variable?

On Linux, assuming gdal/data supporting files are installed under /usr/local/share/gdal/data and Bash-like shell, export the variable as follows:

$ export GDAL_DATA=/usr/local/share/gdal/data

Refer to manual of your shell to learn how to set the GDAL_DATA variable permanently.

On Windows, assuming supporting files are located under C:\GDAL\data, in order to set the variable in current console session:

C:\> set GDAL_DATA=C:\GDAL\data

It's also possible to set GDAL_DATA variable permanently, as system-wide variable, so it's always available. Follow the instructions of How To Manage Environment Variable guide.

Note: See TracWiki for help on using the wiki.