Detecting Visual C++ version in NMAKE makefile

Traditionally when building GDAL/OGR, GEOS or libLAS using NMAKE users specify version of Visual C++ compiler being used as value of MSVC_VER macro. This macros is not required but it’s recommended, so NMAKE can compose best possible set of compilation and linking flags for particular version of Visual C++. For instance, command specifying Visual C++ 8.0 (Visual Studio 2005) looks like this:

nmake -f makefile.vc MSVC_VER=1400

Recently, I hacked libLAS makefiles (and GEOS makefiles too), so Visual C++ version can be determined (semi-)automatically. NMAKE 1.62 or higher reports its version as value of _NMAKE_VER macro. The solution is to defined compiler version based on version of NMAKE tool:

Update 2009-04-03: Added _NMAKE_VER number 9.00.21022.08

!IF "$(_NMAKE_VER)" == ""
MSVC_VER = 4.0
!ERROR *** Prehistoric version of Visual C++
!ELSEIF "$(_NMAKE_VER)" == "162"
MSVC_VER = 5.0
!ERROR *** Prehistoric version of Visual C++
!ELSEIF "$(_NMAKE_VER)" == "6.00.8168.0"
MSVC_VER = 6.0
MSC_VER = 1200
!ERROR *** Prehistoric version of Visual C++
!ELSEIF "$(_NMAKE_VER)" == "7.00.9466"
MSVC_VER = 7.0
MSC_VER = 1300
!ELSEIF "$(_NMAKE_VER)" == "7.10.3077"
MSVC_VER = 7.1
MSC_VER = 1310
!ELSEIF "$(_NMAKE_VER)" == "8.00.50727.42"
MSVC_VER = 8.0
MSC_VER = 1400
!ELSEIF "$(_NMAKE_VER)" == "8.00.50727.762"
MSVC_VER = 8.0
MSC_VER = 1400
!ELSEIF "$(_NMAKE_VER)" == "9.00.21022.08"
MSVC_VER = 9.0
MSC_VER = 1500
!ELSEIF "$(_NMAKE_VER)" == "9.00.30729.01"
MSVC_VER = 9.0
MSC_VER = 1500
!ELSE
MSVC_VER = 0.0
MSC_VER = 0
!ENDIF

Later macros MSVC_VER and MSC_VER can be used to report Visual C++ version:

!IF "$(MSVC_VER)" == "0.0" && "$(MSC_VER)" == "0"
!MESSAGE *** Cannot determined Visual C++ version
!ERROR *** Aborting make job
!ELSE
!MESSAGE *** Using Microsoft NMAKE version $(_NMAKE_VER)
!MESSAGE *** Using Microsoft Visual C++ version $(MSVC_VER)
!MESSAGE *** Using Microsoft C/C++ version $(MSC_VER)
!ENDIF

This is not a rocket science, but it seems to work well and it frees users from manual specification of Visual C++ version. I’m not sure how the NMAKE version numbers vary across Visual Studio versions and builds. It would be good collect these version numbers to make the solution reliable. So, I’d be thankful if readers using Visual Studio 2002, 2003, 2005 and 2008 or newer :-) could report their NMAKE versions directly to me or post them as comments below.

Building PostGIS using Visual C++

I don’t like MinGW. I’ve been dreaming about building PostGIS using Visual C++ – the native development toolset for Windows platform – without being forced to install Unix-like environment inside Windows. Finally, I’ve got motivated enough and decided to make my dreams reality, so here is the story.

First, I collected all run-time dependencies required by PostGIS. I intentionally used the word run-time to indicate I’m not going to install MinGW neither Cygwin or any other GCC-for-Windows package. GNU make is also not required.

I use PostGIS source code from trunk in the Subversion repository.

Dependencies

There are only 3 software packages required:

  1. PostgreSQL 8.3.6official Win32 binaries and source code
  2. GEOS – build from sources, it’s safe to grab SVN trunk
  3. PROJ.4 – also build from sources and also from SVN trunk

I installed the PostgreSQL 8.3.6 without PostGIS extensions, as I’m going to provide my own :-), using default location c:\Program Files\PostgreSQL\8.3. The source code of PostgreSQL 8.3.6 went to d:\dev\postgresql\postgresql-8.3.6.

Short note on directories layout using for projects downloaded directly from repositories. Root path of source tree of each project have the same layout: D:\dev\PROJECT\_svn\trunk. For Visual Studio projects, these paths are defined as macros in postgis.vsprops (Visual C++ Property Sheet), so it should be easy to redefine them without any need to hack other project settings like Additional Include Directories and others.

Continue reading

Visual C++ Toolkit 2003 still in use

Charles Petzold's TattooIn 2004, Microsoft published Visual C++ Toolkit 2003 – full version of Visual C++ 2003 optimizing compiler (version 1310) available free of charge. It was the first free, good and almost complete implementation of C++ programming language by Microsoft. It is quite old but still used by many developers.

The Toolkit is fairly complete, but you can not avoid a few hacks if you want to use it :-) So, I’ve decided to collect them all in one place to help building projects like GEOS, libLAS or GDAL/OGR with the Visual C++ Toolkit 2003.

Installation

First, installation of the following packages is required:

  1. Microsoft .NET Framework SDK 1.1
  2. Microsoft Platform SDK for Windows Server 2003 R2
  3. Microsoft Visual C++ Toolkit 2003 (no longer available from Microsoft website, just be persistent cuiling for it)

Hacks

This is list of hacks like installation of missing components and fixing a project makefiles:

  1. The .NET Framework SDK 1.1 installation (listed above) is required in order to get C Run-Time libraries installed: msvcrt.lib and msvcrtd.lib. The .NET SDK installer will copy these files (and a few other components) to directories located in:

    C:\Program Files\Microsoft Visual Studio .NET 2003
    
  2. Surprisingly, import library for C++ Run-Time Library msvcp71.dll is not included in the Visual C++ Toolkit 2003 distribution. Missing files can be downloaded from CERN server: msvcprt.lib and msvcprt.def. Copy them into

    C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib
    
  3. The Toolkit does not include lib.exe utility – Microsoft Library Manager. Fortunately, lib.exe is just a simple wrapper on Microsoft Incremental Linker – link.exe. So, in your NMAKE makefiles replace lib.exe (or lib) command with:

    link.exe /lib
    

    Alternatively, you can build custom lib.exe wrapper using lib.c program. Recently, I’ve fixed NMAKE makefiles of GEOS (r2190) and libLAS (r876) projects using the former option.

Environment

Most of articles about Visual C++ Toolkit 2003 and Platform SDK installation procedure suggest to permanently update environment variables like INCLUDE, LIB and PATH. Personally, I don’t like this approach. Instead, I write a simple SET_MSVC71.BAT script which I execute in console window before I run NMAKE to build a software project using Visual C++ Toolkit 2003.

The script I use consists of three commands:

@echo off
CALL "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\SetEnv.Cmd"
CALL "C:\Program Files\Microsoft Visual C++ Toolkit 2003\vcvars32.bat"
CALL "C:\Program Files\Microsoft.NET\SDK\v1.1\Bin\sdkvars.bat"

Copy this script to location that is available from the PATH.

Sample build – libLAS

Below, a few simple steps are presented of using Visual C++ Toolkit 2003 and environment configured as presented above to build libLAS project. The same procedure should work for projects like GEOS or GDAL/OGR.

  1. Run Command Prompt (cmd.exe)
  2. Configure environment by executing SET_MSVC71.BAT script:

    C:\> SET_MSVC71.BAT
    

    Check if basic commands are available: cl.exe, nmake.exe, link.exe.

  3. Go to libLAS source code directory:

    C:\> cd dev\liblas\trunk
    
  4. Run NMAKE command to build libLAS library and utilities:

    C:\dev\liblas\trunk> nmake /f makefile.vc
    

Good luck!

FWTools mirrored

Short announcement, today I set up small mirror for FWTools – Open Source GIS Binary Kit for Windows and Linux. It’s available through HTTP under http://fwtools.loskot.net.

Recently, some users reported they have problems with accessing the main FWTools website from various countries, like China, so perhaps this mirror will help them to access the package without any problems.

Please, drop me a note if you’ve encountered problems with accessing the fwtools.loskot.net server.

Spread the FWTools!

Update 2007-09-14 06:50:12 UTC

Added download statistics – http://loskot.net/stats_fwtools.php

Update 2007-09-07 20:44:47 UTC

I think it may be helpful if users know geographical location of the fwtools.loskot.net mirror:

  • IP: 67.19.42.2
  • City: Dallas Texas
  • Country: United States
  • Time Zone: CST

GEOS has moved to Subversion

Yesterday, Paul Ramsey from Refractions Research announced that GEOS project has moved to Subversion repository.

The new repository is available here through HTTP protocol. In order to checkout main development branch (trunk) of the GEOS sources, just run following command as anonymous user, without giving any username or password:

svn checkout http://svn.refractions.net/geos/trunk geos

All current commiters should be able to log in using their existing accounts and passwords.

FWTools 1.0.5 Released

Today, Frank Warmerdam announced new release of his FWTools 1.0.5. Full announcement can be found in FWTools mailing list archives, here.

What’s new in the FWTools 1.0.5?

  • Bug fixes and new features
  • Enabled GEOS support in MapServer
  • Enabled MrSID support (on Windows) by default, as opposed to as a plugin.

Next FWTools releases should also bring MrSID support for Linux users.

FWTools is a set of Open Source GIS binaries for Windows and Linux systems produced by Frank Warmerdam.