Build with libkml

The LIBKML driver must be compiled against the latest version of LibKML (*not* version 1.2). The latest source code of libkml is at

The LibKML source code comes with two Visual Studio 2005 project files - Use the one at the "msvc" folder.


That solution does not include all the needed project, so you should add it after loading the solution on VS 2005.


Note that from the SVN checkout there are more than source code but also some pre-build third part libraries. Those libraries are not build by the existing VS projects but they are going to be needed to build the LibKML driver.


You should make sure that you have build the whole solution, all the projects, in Release mode preferably.

Now, you should update the file "nmake.opt" at GDAL root folder, uncommenting the lines related to libkml and changing LIBKML_DIR to reflect where LibKML is in your system.

# Uncomment out the following lines to enable LibKML support.
LIBKML_DIR = C:/Folder Path/libkml
LIBKML_INCLUDE = -I$(LIBKML_DIR)/src -I$(LIBKML_DIR)/third_party/boost_1_34_1
LIBKML_LIBS =	$(LIBKML_LIBRARY)/libkmlbase.lib \
		$(LIBKML_LIBRARY)/libkmlconvenience.lib \
		$(LIBKML_LIBRARY)/libkmldom.lib \
		$(LIBKML_LIBRARY)/libkmlengine.lib \
		$(LIBKML_LIBRARY)/libkmlregionator.lib \
		$(LIBKML_LIBRARY)/libkmlxsd.lib \
		$(LIBKML_LIBRARY)/minizip_static.lib \
		$(LIBKML_DIR)/third_party\expat.win32/libexpat.lib \
		$(LIBKML_DIR)/third_party\uriparser-0.7.5.win32/release/uriparser.lib \
		$(LIBKML_DIR)/third_party\zlib-1.2.3.win32/lib/minizip.lib \

Now you can either rebuild, clean and build, all the GDAL project.

nmake -f clean
nmake -f 
nmake -f install

Or you can move to the driver folder and build the driver as a OGR plugin and copy the dll to gdalplugins folder.

.\gdal> cd ogr\ogrsf_frtms\libkml
.\gdal\ogr\ogrsf_frtms\libkml> nmake -f ogr_LIBKML.dll
.\gdal\ogr\ogrsf_frtms\libkml> copy ogr_LIBKML.dll <gdal path>\bin\gdalplugins

Visual Studio 2017/2015 notes::

You may get an error of "c2137 empty character constant"; edit the file: src\kml\base\ and change line #43 to:

  std::wstring wstr(str.length(), L'\0');

Testing the driver

To test if the driver is been loaded:

.\> ogrinfo --formats
Supported Formats:
  -> "ESRI Shapefile" (read/write)
  -> "MapInfo File" (read/write)
  -> "UK .NTF" (readonly)
  -> "SDTS" (readonly)
  -> "TIGER" (read/write)
  -> "S57" (read/write)
  -> "DGN" (read/write)
  -> "VRT" (readonly)
  -> "REC" (readonly)
  -> "Memory" (read/write)
  -> "BNA" (read/write)
  -> "CSV" (read/write)
  -> "GML" (read/write)
  -> "GPX" (read/write)
  -> "LIBKML" (read/write)

And if you have a sample file:

.\> ogrinfo sample.kmz
INFO: Open of `sample.kmz'
      using driver `LIBKML' successful.
1: 0
Last modified 4 years ago Last modified on Aug 24, 2018, 2:45:22 PM
Note: See TracWiki for help on using the wiki.