ArcGIS C++ development with nmake and the Windows command prompt


Setting up a compiler for use from the command prompt

From the command prompt you have your choice of supported compilers; your first step will be to select one and prepare it for use. The command-line build tools of Visual Studio are not available by default, so you need to use a provided batch file, vcvars32.bat, to configure one of the Visual Studio compilers for command-line compilation and execution.

Accessing the Visual Studio 2005 compiler from the command line

The command-line build tools of Visual Studio are not available by default. However, Visual Studio 2008 includes a command prompt that makes the tools available. To open the command prompt and access these tools, go to the Start menu > Programs > Microsoft Visual Studio 2008 > Visual Studio Tools > Visual Studio 2008 Command Prompt.
When opened, the prompt automatically runs a batch file, vcvars32.bat, that makes the build tools available. The vcvars32.bat file's default location is \Program Files\Microsoft Visual Studio 8\Vc\bin.

Setting up your application

Open your favorite text editor and begin writing your code. Use a makefile to set the following include directories, and compiler options. If desired, you can utilize the template Makefile.Windows provided with ArcGIS Engine. Refer to the next section for details on this template. The steps below assume that you have installed to the default location.
  1. Use the /I compiler option to add \Program Files\ArcGIS\DeveloperKit10.0\include\CPPAPI and \Program Files\ArcGIS\Engine10.0\com as additional include directories. If you did not install to the default location, find and use your install location to add the \include\CPPAPI and \Com folders as include directories.
  2. Use the /D compiler option to define the ESRI_WINDOWS symbol to direct the compiler to read the Windows support headers from within ArcSDK.h.
  3. Use the /GX compiler flag to enable synchronous exception handling.
  4. Use the /NOLOGO compiler flag to prevent display of a compiler startup banner and informational compiler messages.

Customizing the template makefile

As a convenience, a template makefile—Makefile.Windows—is included with ArcGIS Engine for your use. Makefile.Windows can be found in <install dir>/ArcGIS/DeveloperKit10.0/Samples/ArcObjectsCPP/MakefileTemplates. The following steps highlight the specific areas of the file that must be customized for it to be used in your development process. The modifications shown are based on an application that is written in single code and header files, my_application.cpp and my_application.h, and produces an executable which takes in a single file at runtime. The comment text used here to describe the code of the makefile has been modified from the actual comments within the file to reflect the steps being taken.
  1. Throughout the makefile, update the program name, currently 'basic_sample', to reflect your application name. In this example, my_application is the program name. 

        # Set up the program name
        PROGRAM = my_application.exe
        ...
        # Program name updates - source and object file lists
        CPPSOURCES = my_application.cpp
        CPPOBJECTS = my_application.obj
        ...
        # Program name updates - dependencies list
        my_application.obj: my_application.cpp my_application.h
  1. The compiler options outlined in Steps 2 through 4 above have been set for you; however, you need to complete Step 1 yourself in order to prepare the template for use in your applications. Although the compiler options have already been set in the template, the line is included here to illustrate the use of the built-in CPPFLAGS macro.

        # Setting up the include directories
        INCLUDEDIRS = \
        /I "C:\Program Files\ArcGIS\DeveloperKit10.0\include\CPPAPI" \
        /I "C:\Program Files\ArcGIS\Engine10.0\com"
        ...
        # Setting up the compiler options
        CPPFLAGS = /DESRI_WINDOWS $(INCLUDEDIRS) /nologo /GX
  1. Provide dependencies lists for your application. This line was also shown in Step 1 to illustrate the update of the program name.

        # Program name updates - dependencies list
        my_application.obj: my_application.cpp my_application.h
With your makefile prepared, you are ready to write your code. Don't forget to start by including ArcSDK.h!

Compiling your application

Once Makefile.Windows is ready to compile your application, you can compile from the command line by typing 'nmake /f Makefile.Windows'.

Running your application

You can either invoke your application directly or through the makefile. If you choose to invoke it directly, you will need to provide command-line parameters from the command line. To use the makefile to run an ArcGIS Engine command-line application you must set up the command-line parameters in the makefile. Update your makefile to include variables for each input parameter and a run target.
An example of these modifications is shown below:

    # Setting up the program argument
    INPUT = C:\Data\inputfile
    ...
    # Setting up a run target
    run:
        $(PROGRAM) $(INPUT)
Once Makefile.Windows is ready for use with your application, you will be able to run from the command line by typing 'nmake /f Makefile.Windows run'.