Building TinyOWS on Windows with MSVC
30.04.2011 10:59 · GIS · tinyows, howto
A small tutorial on how to build the current version of TinyOWS (the so-called trunk) under Windows XP Professional using Microsoft Visual C++ 2008 Express Edition and libraries from OSGeo4W.
Preparation
First, we need to set up the build environment. Let’s use instructions written by Florian Hillen as a starting point.
Microsoft Visual C++ 2008 Express
Download the Microsoft Visual C++ 2008 Express Web Installer from https://visualstudio.microsoft.com/downloads/. You can also download an ISO image containing all the required components.
Install everything except MSDN and SQL Server, these are not required. If you installed Visual C++ 2008 Express Edition from the web rather than from an ISO file, MSVC EE will ask you to register the product the first time you start it. This is done with the free Windows Live ID that you need to create.
Microsoft Platform SDK for Windows Server 2003 R2
Download the Microsoft Platform SDK for Windows Server 2003 R2 web installer from https://www.microsoft.com/en-us/download/details.aspx?id=15656.
Depending on the platform you are using, select the desired file:
- PSDK-amd64.exe
- PSDK-ia64.exe
- PSDK-x86.exe
Install it into the default folder and select the following options:
Configuration Options
+ Register Environmental Variables (Yes)
Microsoft Windows Core SDK
+ Tools (Yes)
+ Tools (AMD 64 Bit) (No, если это не ваша платформа)
+ Tools (Intel 64 Bit) (No, если это не ваша платформа)
+ Build Environment
+ Build Environment (AMD 64 Bit) (No, если это не ваша платформа)
+ Build Environment (Intel 64 Bit) (No, если это не ваша платформа)
+ Build Environment (x86 32 Bit) (Yes)
+ Documentation (No)
+ Redistributable Components (Yes)
+ Sample Code (No)
+ Source Code (No)
+ AMD 64 Source (No)
+ Intel 64 Source (No)
Microsoft Web Workshop (Yes)
+ Build Environment (Yes)
+ Documentation (No)
+ Sample Code (No)
+ Tools (No)
Microsoft Internet Information Server (IIS) SDK (No)
Microsoft Data Access Services (MDAC) SDK (Yes)
+ Tools
+ Tools (AMD 64 Bit) (No)
+ Tools (AMD 64 Bit) (No)
+ Tools (x86 32 Bit) (Yes)
+ Build Environment
+ Tools (AMD 64 Bit) (No)
+ Tools (AMD 64 Bit) (No)
+ Tools (x86 32 Bit) (Yes)
+ Documentation (No)
+ Sample Code (No)
Microsodt Installer SDK (No)
Microsoft Table PC SDK (No)
Microsoft Windows Management Instrumentation (No)
Microsoft DirectShow SDK (No)
Microsoft Media Services SDK (No)
Debuggin Tools for Windows (Yes)
It is not recommended to install the newer version of the SDK — Windows SDK for Windows Server 2008 and .NET Framework 3.5. This post assumes that you are using the Windows Server 2003 R2 Platform SDK.
Visual Studio configuration
Start Microsoft Visual C++ Express and set the following paths in “Tools → Options → Projects and Solutions → VC++ Directories”.
Note
I will assume that OSGeo4W was installed in the default directoryC:\OSGeo4W
. If this is not the case, please make the appropriate changes.Section “Executable files”
c:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin
Section “Include files”
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\atl
C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\mfc
Section “Library files”
c:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\
Close Microsoft Visual C++ Express and go to the C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools
directory. Open the vsvars32.bat
file and add the following paths to the lines starting with @set
:
@set PATH=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin;%PATH%
@set INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include;%INCLUDE%
@set INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\mfc;%INCLUDE%
@set LIB=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib;%LIB%
@set LIB=%LIB%;C:\OSGeo4W\lib
Also check that the following environment variables exist and have the correct values:
INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include\
LIB=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib\
LIB_DIR=C:\OSGeo4W
PATH=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\.;C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin\WinNT\.;C:\Program Files\Microsoft Visual Studio 9.0\VC\bin;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools;C:\OSGeo4W\bin
Our build environment is now configured.
Installing dependencies
Now we need to get all the TinyOWS dependencies, which are:
- libxml2 (>=2.6.20)
- iconv
- regex
- fastcgi
- Flex
- PostgreSQL (with libpq headers)
- PostGIS (>=1.5.0)
Everything except the last three items can be installed using OSGeo4W. I will assume that everything is installed in the default directory (C:\OSGeo4W
). If this is not the case, change the paths accordingly.
Download Flex and install it in the C:\OSGeo4W
directory.
OSGeo4W only provides the PostgreSQL client library — libpq, so we need to download and install the required version of PostgreSQL (e.g. 9.0.4). Then use StackBuilder to install PostGIS 1.5.0 or later. If, for some reason, you cannot use StackBuilder, PostGIS can be installed using the standard installer.
Getting the TinyOWS code
Download and install Subversion. Add the Subversion directory to your PATH
environment variable.
Create a directory where the TinyOWS code will be located. Go to “Start → Run”, type cmd
and press Enter, then navigate to the created directory and get the TinyOWS source code using the following command:
svn co http://www.tinyows.org/svn/tinyows/trunk
Building and installing
I assume that PostgreSQL is installed in the default directory C:\Program Files\PostgreSQL\9.0
and that the TinyOWS source code is in the directory D:\devel\cpp\tinyows
. If you have installed PostgreSQL or downloaded the TinyOWS code to a different directory, make the necessary changes.
Go to the directory with the TinyOWS source code created in the previous step, open the nmake.opt
file in a text editor, and start editing it:
- find the
TINY_BASE
variable (in my case it is line 36) and specify the path to the TinyOWS source code directoryTINY_BASE = D:\devel\cpp\tinyows
- if necessary, change the
BINDIR
variable (line 46). The path specified in this variable determines the location of the generated TinyOWS binary after successful compilationBINDIR = $(TINY_BASE)\bin
- Find the
POSTGIS_DIR
variable (line 102) and specify the path to the installed PostgreSQL (note the quotes!)POSTGIS_DIR ="C:\Program Files\PostgreSQL\9.0"
- specify the directory containing the libxml and iconv files (lines 112 and 125). As we have installed these libraries using OSGeo4W, the directory will be the same
LIBXML_DIR=c:\OSGeo4W ICONV_DIR=c:\OSGeo4W
- line 143 specifies the location of the regex library files
REGEX_DIR=C:\OSGeo4W\include\regex-0.12
- lines 183 and 185 are amended as follows
POSTGIS_INC=-I"c:\Program Files\PostgreSQL\9.0\lib\libpq" -I"c:\Program Files\PostgreSQL\9.0\include" POSTGIS_LIB="c:\Program Files\PostgreSQL\9.0\lib\libpq.lib"
Save your changes and close the editor.
Edit the D:\devel\cpp\tinyows\Makefile.vc
file. Add C:\OSGeo4W\lib\libfcgi.lib
to the end of line 19, so that after editing it looks like this:
CFLAGS=$(BASE_CFLAGS) $(TINY_CFLAGS) c:\OSGeo4W\lib\libfcgi.lib
Open the D:\devel\cpp\tinyows\src\ows_define.h.in
file and change line 27 to look like this:
#if TINYOWS_DEBUG
Line 32 should look like this:
#define TINYOWS_FCGI 1
If you don’t need FastCGI support, replace 1 with 0.
Warning
Performance is significantly reduced when FastCGI support is disabled.Now we need to edit the file C:\OSGeo4W\include\regex-0.12\regex.c
. Open it in a text editor and replace lines 4876-4880
regerror (errcode, preg, errbuf, errbuf_size)
int errcode;
const regex_t *preg;
char *errbuf;
size_t errbuf_size;
with the following code
regerror (int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
The preparation is done, now we can build TinyOWS.
Open the Visual Studio command prompt by selecting “Start → Programs → Microsoft Visual C++ 2008 Express Edition → Visual Studio Tools → Visual Studio 2008 Command Prompt”. Change to the directory containing the TinyOWS source code and run
nmake /f Makefile.vc
If the compilation completes without errors, a bin
subdirectory will be created in the root of the source directory. Within it, you will find the files tinyows.exe
(the server itself) and tiny.lib
(the library file). The tinyows.exe
file should be copied to the cgi-bin
directory of the web server.