Two days ago, someone asked me on the Oschian MinGW compile gdal some problems, and then I simply compiled once, recording the compilation process.
This article was written in May 2017, when there was a draft box, which was only seen today. It may not be available for the latest version now.
1. Preparation
1, install MinGW, I installed is the version of Mingw-w64 x86_64-7.1.0-win32-seh-rt_v5-rev0
.
2. Prepare a Unix-like simulation run environment. I use Git's msys directly here, you can also download Cygwin.
3, download and decompression gdal source code
Note:the installation path of the MinGW must have no spaces, and if so, the compiler will not be found after compilation (absolute paths must be specified, and the paths need to be enclosed in quotation marks). Gdal the source code decompression path also do not have spaces.
2. Generate makefile
In the Msys environment, enter the gdal-2.1.2
source directory, run the command to generate the Gnumakefile file
# 将mingw的路径导入环境变量PATHexport PATH=$PATH:/c/mingw-w64/x86_64-7.1.0-win32-seh-rt_v5-rev0/mingw64/bin# 生成Makefile文件./configure --prefix=/z/gdal_2.1.2_mingw64 --without-libtool## --prefix 指定安装路径## --without-libtool 不使用libtool(因为我当前环境没有)## 默认是静态库和动态库都生成,使用libtool可能只能生成静态库,因为它不知道在当前平台如何生成动态库。
Attention
The above procedure will generate and file normally without GNUMakefile
errors GDALmake.opt
.
Because we do mingw64
not have a path to identify /c/xxx
such paths (this is the path under Msys), we need to modify the GDALmake.opt
file to GDAL_ROOT
Modify the value in C:\xxx
this form.
3. Compiling
Run the following command to compile
mingw32-make
4, the compilation encountered errors and solutions
The following error occurred during compilation
1. When the static library is generated
ar
Prompt argument list too long
AR r z:/gdal-2.1.2/libgdal.a z:/gdal-2.1.2/frmts/o/*.o z:/gdal-2.1.2/gcore/*.o z:/gdal-2.1.2/port/*.o Z:/gdal-2.1.2/ ALG/*.O Z:/GDAL-2.1.2/APPS/COMMONUTILS.O Z:/GDAL-2.1.2/APPS/GDALINFO_LIB.O Z:/gdal-2.1.2/apps/gdal_translate_ LIB.O z:/gdal-2.1.2/apps/gdalwarp_lib.o z:/gdal-2.1.2/apps/ogr2ogr_lib.o z:/gdal-2.1.2/apps/gdaldem_lib.o Z:/ GDAL-2.1.2/APPS/NEARBLACK_LIB.O Z:/GDAL-2.1.2/APPS/GDAL_GRID_LIB.O Z:/GDAL-2.1.2/APPS/GDAL_RASTERIZE_LIB.O Z:/ GDAL-2.1.2/APPS/GDALBUILDVRT_LIB.O z:/gdal-2.1.2/ogr/ogrsf_frmts/o/*.o./ogr/ogrgeometryfactory.o./ogr/ OGRPOINT.O./ogr/ogrcurve.o./OGR/OGRLINESTRING.O/ogr/ogrlinearring.o/ogr/ogrpolygon.o./ogr/ogrutils.o./ogr/ ogrgeometry.o./ogr/ogrgeometrycollection.o./OGR/OGRMULTIPOLYGON.O/ogr/ogrsurface.o./ogr/ogrmultipoint.o./ogr/ OGRMULTILINESTRING.O./ogr/ogrcircularstring.o./ogr/ogrcompoundcurve.o./ogr/ogrcurvepolygon.o./ogr/ OGRCURVECOLLECTION.O./ogr/ogrmulticurve.o./OGR/OGRMULTISURFACE.O/ogr/ogr_api.o./ogr/ogrfeature.o./ogr/ OgrfeaturedefN.O./ogr/ogrfeaturequery.o./OGR/OGRFEATURESTYLE.O/ogr/ogrfielddefn.o./ogr/ogrspatialreference.o./ogr/ogr_ SRSNODE.O./ogr/ogr_srs_proj4.o./OGR/OGR_FROMEPSG.O/ogr/ogrct.o/ogr/ogr_opt.o./ogr/ogr_srs_esri.o./ogr/ogr_ SRS_PCI.O./ogr/ogr_srs_usgs.o./OGR/OGR_SRS_DICT.O/ogr/ogr_srs_panorama.o./ogr/ogr_srs_ozi.o./ogr/ogr_srs_ ERM.O./ogr/swq.o./OGR/SWQ_EXPR_NODE.O/ogr/swq_parser.o/ogr/swq_select.o./ogr/swq_op_registrar.o./ogr/swq_op_ GENERAL.O./ogr/ogr_srs_validate.o./OGR/OGR_SRS_XML.O/ogr/ograssemblepolygon.o./ogr/ogr2gmlgeometry.o./ogr/ gml2ogrgeometry.o./ogr/ogr_expat.o./ogr/ogrpgeogeometry.o/ogr/ogrgeomediageometry.o./ogr/ogr_geocoding.o./ogr /OSR_CS_WKT.O./ogr/osr_cs_wkt_parser.o./ogr/ogrgeomfielddefn.o./ogr/ograpispy.o/usr/bin/sh:/c/mingw-w64/x86_ 64-7.1.0-win32-seh-rt_v5-rev0/mingw64/bin/ar:argument list too longgnumakefile:47:recipe for Target ' Z:/gdal-2.1.2/ Libgdal.a ' failedmingw32-make[1]: * * * [Z:/GDAL-2.1.2/LIBGDAL.A] Error 126
This can be done by modifying the gdal_obj
variable in the gnumakefile
file by splitting the original gdal_obj
into multiple, and then The action of the Gdal_slib
target is modified to generate multiple static libraries and then synthesize one.
Because of this large amount of modification, I do not modify, directly outside the use of command generation LIBGDAL.A
. My source directory here is z:/gdal-2.1.2
.
# first divide it into four parts, generate four static libraries # Note that the parameters of this four static library for AR generation are Srar sr basepart.a z:/gdal-2.1.2/frmts/o/*.o z:/gdal-2.1.2/gcore/*.o z:/gdal-2.1. 2/PORT/*.O z:/gdal-2.1.2/alg/*.o ar sr appspart.a z:/gdal-2.1.2/apps/commonutils.o Z:/GDAL-2.1.2/APPS/GDALINFO_LIB.O Z:/GDAL-2.1.2/APPS/GDAL_TRANSLATE_LIB.O Z:/GDAL-2.1.2/APPS/GDALWARP_LIB.O Z:/GDAL-2.1.2/APPS/OGR2OGR_LIB.O Z:/ GDAL-2.1.2/APPS/GDALDEM_LIB.O Z:/GDAL-2.1.2/APPS/NEARBLACK_LIB.O Z:/GDAL-2.1.2/APPS/GDAL_GRID_LIB.O Z:/gdal-2.1.2 /APPS/GDAL_RASTERIZE_LIB.O Z:/gdal-2.1.2/apps/gdalbuildvrt_lib.oar SR ogrpart1.a Z:/gdal-2.1.2/ogr/ogrsf_frmts/o/* . O./ogr/ogrgeometryfactory.o./ogr/ogrpoint.o./ogr/ogrcurve.o./OGR/OGRLINESTRING.O/OGR/OGRLINEARRING.O./ogr/ OGRPOLYGON.O./ogr/ogrutils.o./ogr/ogrgeometry.o/ogr/ogrgeometrycollection.o./ogr/ogrmultipolygon.o./ogr/ OGRSURFACE.O./ogr/ogrmultipoint.o./ogr/ogrmultilinestring.o./ogr/ogrcircularstring.o./ogr/ogrcompoundcurve.o. OGR/OGRCURVEPOLYGON.O./ogr/ogrcurvecollection.o./ogr/ogrmulticurve.o./ogr/ogrmultiSURFACE.O./ogr/ogr_api.o./OGR/OGRFEATURE.O/ogr/ogrfeaturedefn.o./ogr/ogrfeaturequery.o./OGR/OGRFEATURESTYLE.O ./ogr/ogrfielddefn.o./ogr/ogrspatialreference.o./ogr/ogr_srsnode.o./ogr/ogr_srs_proj4.o./ogr/ogr_fromepsg.o. OGR/OGRCT.O ar sr ogrpart2.a/ogr/ogr_opt.o/ogr/ogr_srs_esri.o/ogr/ogr_srs_pci.o/ogr/ogr_srs_usgs.o./ogr/ogr_ SRS_DICT.O./ogr/ogr_srs_panorama.o./OGR/OGR_SRS_OZI.O/ogr/ogr_srs_erm.o/ogr/swq.o./ogr/swq_expr_node.o./ogr/ SWQ_PARSER.O./ogr/swq_select.o./OGR/SWQ_OP_REGISTRAR.O/ogr/swq_op_general.o./ogr/ogr_srs_validate.o./ogr/ogr_ SRS_XML.O./ogr/ograssemblepolygon.o./ogr/ogr2gmlgeometry.o/ogr/gml2ogrgeometry.o./ogr/ogr_expat.o./ogr/ ogrpgeogeometry.o./ogr/ogrgeomediageometry.o./ogr/ogr_geocoding.o./ogr/osr_cs_wkt.o./ogr/osr_cs_wkt_parser.o. OGR/OGRGEOMFIELDDEFN.O./ogr/ograpispy.o# then synthesize an AR r z:/gdal-2.1.2/libgdal.a basepart.a appspart.a ogrpart1.a ogrpart2.a
Note: the parameters used when generating four static libraries are sr
, this means that one is generated ranlib
(only packaging .o
files, not processing. o symbol table). When generated later libgdal.a
, parameters are used, which means that the r
members of the static library are updated after packaging __.SYMDEF
.
2. When the dynamic library is generated
g++
Prompt argument list too long
g++-shared z:/gdal-2.1.2/frmts/o/*.o z:/gdal-2.1.2/gcore/*.o z:/gdal-2.1.2/port/*.o Z:/gdal-2.1.2/alg/*.o Z:/ GDAL-2.1.2/APPS/COMMONUTILS.O Z:/GDAL-2.1.2/APPS/GDALINFO_LIB.O Z:/GDAL-2.1.2/APPS/GDAL_TRANSLATE_LIB.O Z:/ GDAL-2.1.2/APPS/GDALWARP_LIB.O Z:/GDAL-2.1.2/APPS/OGR2OGR_LIB.O Z:/GDAL-2.1.2/APPS/GDALDEM_LIB.O Z:/gdal-2.1.2/ APPS/NEARBLACK_LIB.O Z:/GDAL-2.1.2/APPS/GDAL_GRID_LIB.O Z:/GDAL-2.1.2/APPS/GDAL_RASTERIZE_LIB.O Z:/gdal-2.1.2/ APPS/GDALBUILDVRT_LIB.O z:/gdal-2.1.2/ogr/ogrsf_frmts/o/*.o./ogr/ogrgeometryfactory.o./ogr/ogrpoint.o./ogr/ OGRCURVE.O./ogr/ogrlinestring.o./OGR/OGRLINEARRING.O/ogr/ogrpolygon.o/ogr/ogrutils.o./ogr/ogrgeometry.o./ogr /OGRGEOMETRYCOLLECTION.O./ogr/ogrmultipolygon.o./ogr/ogrsurface.o./ogr/ogrmultipoint.o./ogr/ OGRMULTILINESTRING.O./ogr/ogrcircularstring.o./ogr/ogrcompoundcurve.o./ogr/ogrcurvepolygon.o./ogr/ OGRCURVECOLLECTION.O./ogr/ogrmulticurve.o./OGR/OGRMULTISURFACE.O/ogr/ogr_api.o./ogr/ogrfeature.o./ogr/ OGRFEATUREDEFN.O./ogr/ogrfeaturequery.o./ogr/ogrfeaturestyle.o./OGR/OGRFIELDDEFN.O/ogr/ogrspatialreference.o./ogr/ogr_srsnode.o./ogr/ogr _srs_proj4.o./ogr/ogr_fromepsg.o./OGR/OGRCT.O/ogr/ogr_opt.o/ogr/ogr_srs_esri.o./ogr/ogr_srs_pci.o./ogr/ogr_ SRS_USGS.O./ogr/ogr_srs_dict.o./OGR/OGR_SRS_PANORAMA.O/ogr/ogr_srs_ozi.o/ogr/ogr_srs_erm.o./ogr/swq.o./ogr/ SWQ_EXPR_NODE.O./ogr/swq_parser.o./OGR/SWQ_SELECT.O/ogr/swq_op_registrar.o./ogr/swq_op_general.o./ogr/ogr_srs _VALIDATE.O./ogr/ogr_srs_xml.o./OGR/OGRASSEMBLEPOLYGON.O/ogr/ogr2gmlgeometry.o./ogr/gml2ogrgeometry.o./ogr/ OGR_EXPAT.O./ogr/ogrpgeogeometry.o./ogr/ogrgeomediageometry.o/ogr/ogr_geocoding.o./ogr/osr_cs_wkt.o./ogr/osr_ CS_WKT_PARSER.O./ogr/ogrgeomfielddefn.o./OGR/OGRAPISPY.O Z:/gdal-2.1.2/libgdal.a-lodbc32-lodbccp32-lz-lpthread- Lm-lws2_32-liconv-o z:/gdal-2.1.2/libgdal.so/usr/bin/sh:/c/mingw-w64/x86_64-7.1.0-win32-seh -rt_v5-rev0/mingw64/bin/g++: Argument list too longgnumakefile:52:rEcipe for Target ' z:/gdal-2.1.2/libgdal.so ' failedmingw32-make[1]: * * [z:/gdal-2.1.2/libgdal.so] Error 126
The error here is the same as the reason for generating a static library, and the solution is similar to the above.
You can see the action of the generated target GDAL_LIB
, the variables used (dependent. O and. A) GDAL_SLIB
are consistent with the build. Because we have already generated,,, and so on, basepart.a
appspart.a
so we ogrpart1.a
ogrpart2.a
can create the dynamic library directly (the suffix is changed to DLL).
g++ -shared basepart.a appspart.a ogrpart1.a ogrpart2.a -lodbc32 -lodbccp32 -lz -lpthread -lm -lws2_32 -liconv -o Z:/gdal-2.1.2/libgdal.dll
Note: because of the previous creation of the basepart.a
file, AR uses the parameters to be sr
successful. If the parameter is used r
, the following error is reported:
basepart.a: error adding symbols: Archive has no index; run ranlib to add one
Also note that the above link uses the -liconv
parameter, if not in the generated makefile, the following error will be reported
undefined reference to `[email protected]
MinGW Building Gdal 2.1.2