[Gdal-dev] RE: [Openev-discuss] GDAL compile MinGW

Norman Vine nhv at cape.com
Wed Dec 15 23:09:30 EST 2004


Pete Nagy writes:
> 
> 
> Hello all (my apologies to those on both lists) ->
> 
>   I am now trying to
> compile GDAL with MinGW.  I've hacked a fix to jmorecfg.h to get the libs
> to build, but pymod did not build without some hacks to the paths in the
> GDALMake.opt, and now the apps do not build.  Has anyone built this code
> with MinGW before, or does anyone have any experiences they can share with
> building GDAL and/or these other libraries with gcc or MinGW?  

< following for the archives since this question 
   seems to come up fairly frequently >

to build GDAL with MingW something like the following should work

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

Then after GDAL is built change your GDALMake.opt file to 
reflect your python installation in my case

PYTHON_INCLUDES = -Ic:/Python22/include
PYTHON_LIBS =  -Lc:/Python22/libs/ -lpython22
PYTHON_CFLAGS =  
PYTHON = yes

below find a heavily hacked version of the setup.py
from the TOP GDAL directory that I just built gdal pymod with 
with my MingW system

Note you will have to change the line in the script below

LIBRARY_DIRS = ["./", "d:/usr/mingw/lib"]

to reflect your local system

You need to build and install the MingW Python Link Library 
http://www.mingw.org/MinGWiki/index.php/Python%20extensions

Once you have done this and have built the rest of GDAL

then using the script below thusly

>python setup.py build --force --compiler=mingw32
>python setup.py install --force

should allow you to do

>python
Python 2.2.3 (#42, Jun  4 2003, 10:33:42) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gdal,gdalnumeric
>>> dir()
['__builtins__', '__doc__', '__name__', 'gdal', 'gdalnumeric']
>>> dir(gdal)
['AllRegister', 'Band', 'CE_Debug', 'CE_Failure', 'CE_Fatal', ........
............
>>> dir(gdalnumeric)
['ArrayType', 'BandReadAsArray', 'BandWriteArray', 'CE_Debug' .......

Note This is unsupported
But It works for me and should work for you if you follow the instructions

I will probably not answer any questions so if you have problems 
please ask then on the appropriate list
i.e Python-Discuss or MingW-Users

Good luck

Norman

#!/usr/bin/env python
#******************************************************************************
#  $Id: setup.py,v 1.5 2004/04/25 19:28:45 aamici Exp $
# 
#  Name:     setup.py
#  Project:  GDAL
#  Purpose:  Installation / Install script.
#  Author:   Evgeniy Cherkashin <eugeneai at icc.ru>
# 
#******************************************************************************
#  Copyright (c) 2003, Evgeniy Cherkashin <eugeneai at icc.ru>
# 
#  Permission is hereby granted, free of charge, to any person obtaining a
#  copy of this software and associated documentation files (the "Software"),
#  to deal in the Software without restriction, including without limitation
#  the rights to use, copy, modify, merge, publish, distribute, sublicense,
#  and/or sell copies of the Software, and to permit persons to whom the
#  Software is furnished to do so, subject to the following conditions:
# 
#  The above copyright notice and this permission notice shall be included
#  in all copies or substantial portions of the Software.
# 
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
#  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
#  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
#  DEALINGS IN THE SOFTWARE.
#******************************************************************************
# 
# $Log: setup.py,v $
# Revision 1.5  2004/04/25 19:28:45  aamici
# core -> gcore update
#
# Revision 1.4  2004/01/31 10:14:08  aamici
# fix all stale references after the libtool transition.
# don't install non-python data files.
#
# Revision 1.3  2003/02/07 14:14:00  warmerda
# fixed spelling of python
#
# Revision 1.2  2003/02/07 14:11:03  warmerda
# corrected a few info items, added header
#

import string
from distutils.core import setup, Extension
import os, os.path, glob
from distutils.sysconfig import parse_makefile,expand_makefile_vars

f=open(os.path.join("VERSION"))
v=f.read()
f.close()
del f

version=v.strip()
dllversion=version.replace(".","")
soversion=v[:3]

SOURCES=glob.glob(os.path.join("pymod","*.c*"))
print SOURCES
INCLUDE_DIRS=[os.path.join("gcore"), os.path.join("port"), os.path.join("ogr"), os.path.join("pymod"), ]
LIBRARY_DIRS = ["./", "d:/usr/mingw/lib"]

INCLUDE_FILES = [
	glob.glob(os.path.join("gcore", "*.h")),
	glob.glob(os.path.join("port", "*.h")),
	glob.glob(os.path.join("alg", "*.h")),
	glob.glob(os.path.join("ogr", "*.h")), 
	glob.glob(os.path.join("ogr", "ogrsf_frmts", "*.h")),
	glob.glob(os.path.join("pymod", "*.h"))
]

IF=[]
for i in INCLUDE_FILES:
	IF.extend(i)
INCLUDE_FILES=IF
del IF

HTML_FILES=glob.glob(os.path.join("html", "*"))

DLL="gdal%s.dll" % dllversion
DATA_FILES=[
    ("", [DLL]),
    ("libs", [os.path.join("libgdal.a")]),
    ]

DICT = parse_makefile("GDALMake.opt")

LIBRARIES = ["gdal"]
for lib in string.split(DICT[expand_makefile_vars("LIBS",DICT)]):
    LIBRARIES.append(lib[2:])
LIBRARIES.append("stdc++")

EXTRA_LINK_ARGS=[]

DATA_FILES.append(("include", INCLUDE_FILES))
DATA_FILES.append((os.path.join("doc","gdal"), HTML_FILES))

setup (name = "Python_GDAL",
       version = version,
       description = "Geospatial Data Abstraction Library: Python Bindings",
       author = "Frank Warmerdam",
       #packager = "Evgeniy Cherkashin",
       author_email = "warmerdam at pobox.com",
       #packager_email = "eugeneai at icc.ru",
       url = "http://www.remotesensing.org/gdal/",
       packages = [''],
       package_dir = {'': 'pymod'},
       #extra_path = "gdal",
       ext_modules = [Extension('_gdal',
			sources = SOURCES,
			include_dirs = INCLUDE_DIRS,
			libraries = LIBRARIES,
			library_dirs = LIBRARY_DIRS,
			extra_link_args=EXTRA_LINK_ARGS,
			),
		],
		#data_files = DATA_FILES
	)




More information about the Gdal-dev mailing list