Developing with GTK using Visual Studio 2008 and NMake


Setting up your development environment

This document describes how to build an ArcGIS Engine C++ GTK application using either the Visual Studio IDE or the compiler from the command prompt with NMake. An application using the GTK control widgets is built in the same way as a command-line application, but with a few additional include and library settings. For an introduction to setting up the IDE or command prompt environment and creating a basic ArcGIS Engine C++ application, please refer to the following documents:
  • ArcGIS C++ development in the Visual Studio 2008 IDE
  • ArcGIS C++ development with nmake and the Windows command prompt
The remainder of this document contains instructions for configuring your build environment for use with the ArcGIS C++ Engine GTK control widgets, whether you are using the Visual Studio IDE or NMake at the command prompt. Sections specific to using NMake at the command prompt will be indicated with "(NMake)". Sections specific to the Visual Studio 2008 IDE will be indicated with "(IDE)".

Setting up your application

Setting up an ArcGIS Engine C++ GTK application is like setting up and ArcGIS Engine C++ application. There are only a few libraries, includes, and flags to add to your build.
First, in addition to the basic include paths, you will need to add the GTK include paths to your project or NMakefile. These paths may vary depending on your GTK installation, but they will probably be:
  • <GTK_INSTALL_PATH>\include\gtk-2.0
  • <GTK_INSTALL_PATH>\include\glib-2.0
  • <GTK_INSTALL_PATH>\include\pango-1.0
  • <GTK_INSTALL_PATH>\include\atk-1.0
  • <GTK_INSTALL_PATH>\lib\glib-2.0\include
  • <GTK_INSTALL_PATH>\lib\gtk-2.0\include
You will need to replace "<GTK_INSTALL_PATH>" with the location of your GTK installation. The following instructions assume that your GTK installation path is C:\GTK
(IDE) In your project settings, select Configuration Properties > C/C++. In the "Additional Include Directories" field, enter the required GTK include paths, each separated by a semicolon (";"). Your entry should resemble:
C:\Program Files\ArcGIS\DeveloperKit10.0\include\CPPAPI;C:\Program Files\ArcGIS\Engine10.0\com;C:\GTK\include\gtk-2.0;C:\GTK\include\glib-2.0;C:\GTK\include\pango-1.0;C:\GTK\include\atk-1.0;C:\GTK\lib\glib-2.0\include;C:\GTK\lib\gtk-2.0\include
(NMake) You may wish to use the template Makefile included with ArcGIS Engine—Makefile.WindowsGTK. It can be found in <install dir>/ArcGIS/DeveloperKit10.0/Samples/ArcObjectsCPP/MakefileTemplates. Using a text editor you will change the INCLUDEDIRS macro to the following:
    # Setting up the include directories
    INCLUDEDIRS = \
        /I "C:\Program Files\ArcGIS\DeveloperKit10.0\include\CPPAPI" \
        /I "C:\Program Files\ArcGIS\Engine10.0\com" \
        /I "C:\GTK\include\gtk-2.0" \
        /I "C:\GTK\include\glib-2.0" \
        /I "C:\GTK\include\pango-1.0" \
        /I "C:\GTK\include\atk-1.0" \
        /I "C:\GTK\lib\glib-2.0\include" \
        /I "C:\GTK\lib\gtk-2.0\include"
    ...
    # Setting up the compiler options
    CPPFLAGS = /DESRI_WINDOWS $(INCLUDEDIRS) /nologo /GX
Next, you will need to add the necessary libraries and library paths to your build environment to support the GTK control widgets. The ArcGIS Engine for Windows libraries:
  • gtkctl.lib
  • aoctl.lib
and their location (C:\Program Files\ArcGIS\DeveloperKit10.0\lib) and the GTK libraries:
  • gtk-win32-2.0.lib
  • gobject-2.0.lib
  • glib-2.0.lib
and their location (C:\GTK\lib) must be added to the link directive.
(IDE) In your project settings, select Configuration Properties > Linker > General. In the "Additional Library Dependencies" field, enter the library paths, separated by a semicolon:
C:\Program Files\ArcGIS\DeveloperKit10.0\lib;C:\GTK\lib
In the project settings, select Configuration Properties > Linker > Input. In the "Additional Dependencies" field, enter the libraries, separated by spaces:
gtkctl.lib aoctl.lib gtk-win32-2.0.lib gobject-2.0.lib glib-2.0.lib
(NMake) Using again the template Makefile Makefile.WindowsGTK, change the LINKFLAGS macro to the following:
    # Setting up the libraries and their paths
    LINKFLAGS = \
        /LIBPATH:C:\Program Files\ArcGIS\DeveloperKit10.0\lib \
        gtkctl.lib aoctl.lib \
        /LIBPATH:C:\GTK\lib \
        gtk-win32-2.0.lib gobject-2.0.lib glib-2.0.lib
Following these steps your Visual Studio 2008 IDE or NMake build environment should be ready to build your ArcGIS Engine C++ GTK application.

Compiling your application

Before compiling, make sure you have properly adjusted the project/program name, source files, and their dependencies as described in the documents:
  • ArcGIS C++ development in the Visual Studio 2008 IDE
  • ArcGIS C++ development with nmake and the Windows command prompt
(IDE) To compile an ArcGIS Engine application in Visual Studio 2008, click Build > Build Solution.
(NMake) 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

(IDE) Before you can run an ArcGIS Engine command line application from within Visual Studio 2008, you need to set up the arguments. Arguments are added to your program by customizing your project settings; go to the Project menu > Properties > Debugging item and add any arguments to 'Command Arguments'. Make sure the configuration you are working on is selected in the configuration combo box.
Finally, run the application by clicking Debug > Start Without Debugging or by pressing Ctrl+F5. If you wish to run the application in debug mode, click Debug > Start, or press F5.
(NMake) 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'.