# Compiling psqlODBC on Windows

This page describes how to build the PostgreSQL ODBC Driver on Windows. There are three methods to build: from command line using nmake makefiles, from command line using MSBuild files, and from Visual Studio IDE.

The following 3rd party software are required for the build:

- Microsoft Windows SDK 7.0 (or later), or Microsoft Visual Studio C++ 2005 Edition (or later). Other compilers may work but have not been tested. Download the latest version from Microsoft's download page
- PostgreSQL Client library (libpq.dll) and headers. Download the latest version from the PostgreSQL downloads page. If you download the graphical installer, it is not necessary to install the server. You can pass "--extract-only yes" option to the installer to just extract the files without setting up the server.
- OpenSSL library and header files. Download the latest version from the OpenSSL website.
- WiX Toolset. Required for building the installer. Download the latest version from the WiX Toolset website

For the MSBuild method, you will also need PowerShell.

## Building with nmake.exe

Use NMAKE.exe to build the driver for the currently active target:
`C:\psqlodbc\> nmake /f win64.mak <options>`

Despite the name, win64.mak is used to build both 32-bit and 64-bit binaries. With the Microsoft Windows SDK Command Prompt, you can switch between 32-bit and 64-bit target architectures with `setenv /x86` and `setenv /x64` commands. If using a Visual Studio Command Prompt you can start the x86 or x64 versions from the Start menu, or run `vcvarsall.bat` with appropriate options to switch architectures.

To build the .msi installer file:
`C:\psqlodbc\> nmake /f win64.mak installer`
The resulting installer file goes to installer/x64 or installer/x86 directory.

To build both 32-bit and 64-bit versions in one command:
`C:\psqlodbc\> nmake /f win64.mak world`

The following build options may be used, either on the command line, or by creating a file called "windows-local.mak".

Variable | Values
CFG | Release(default), or Debug
PG_INC | $(PROGRAMFILES)\PostgreSQL\9.3\include
PG_LIB | $(PROGRAMFILES)\PostgreSQL\9.3\lib
SSL_INC | C:\OpenSSL-Win32\include
SSL_LIB | C:\OpenSSL-Win32\lib
ANSI_VERSION | no (If set to "yes", output dll name to psqlodbc30a.dll)
MSDTC | yes

1. UNICODE is the default (psqlodbc35w.dll), unless ANSI_VERSION is selected (psqlodbc30a.dll)
2. libpq.dll is mandatory.
3. If MSDTC == Yes, "pgxalib.dll" is created.
4. If MSDTC is enabled, ANSI_VERSION also creates "pgenlista.dll", or UNICODE creates "pgenlist.dll".

## Building with MSBuild

See winbuild/readme.txt in the source directory for details.

## IDE Method

A Microsoft Visual Studio project file (and workspace) is included in the source tree.

psqlodbc.dsp can be used with Microsoft Visual C++ 6.0.

psqlodbc.proj and psqlodbc.sln can be used with Microsoft Visual C++ 2005 Edition (including the Express edition which can be downloaded free of charge from http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/default.aspx)

Preparation before the build:

1. The Windows distribution of PostgreSQL will install the required headers and libraries into C:\Program Files\PostgreSQL\9.2
2. OpenSSL should be installed into C:\OpenSSL (OpenSSL binaries can be downloaded from http://www.slproweb.com/products/Win32OpenSSL.html)

If you want to change the installation arrangement, it is necessary to edit the project settings.

Note:

The default build settings will create the following driver:

1. UNICODE support.
2. libpq is mandatory.
3. The driver filename is "psqlodbc35w.dll".