Developing with make and Qt using the command prompt


Setting up a compiler for use from the command prompt

Sun Studio 11 (CC) for Solaris; GCC version 3.4 (or later) (g++) for Linux
If your GCC compiler on Linux has not been installed in a standard location, some of your compiled applications may not be able to find libstdc++.so at runtime. In this case, you will need to add this library's directory (usually <gcc-install-dir>/lib) to your LD_LIBRARY_PATH environment variable.

Initializing ArcGIS Engine

With your machine ready for C++ development, there is only a single step to prepare for ArcGIS Engine development, and that is to source the arcgis/init_engine.sh (or .csh, depending on your shell of choice). If you prefer, that can be done in your shell's RC file (.cshrc or .bashrc, for example). Otherwise, you must source that file once per shell.

Setting up your application

Setting up an ArcGIS Engine C++ Qt application is like setting up an ArcGIS Engine C++ application. There are only a few additional libraries, includes, and flags to add to the makefile. For those of you familiar with ArcGIS Engine C++ programming, you will need to add qtctl and aoctl as libraries to link against (that is, add them with the -l flag, as shown in Step 3 below). In addition, you will need to add the qt CFLAGS and LDFLAGS, which will be generated by a package management script called pkg-config. If you are not familiar with ArcGIS Engine C++ programming, all the steps you need to take in preparing your application are discussed below.
Open your favorite text editor and begin writing your code. Use a makefile to set the following include directories, library options, and compiler options.
If desired, you can utilize template makefiles provided with the ArcGIS Engine. Makefile.SolarisQt provides a starting point for Solaris Qt applications, and Makefile.LinuxQt will get you started with Linux Qt applications. Refer to the next section for details on these templates.
Below, $(AGSDEVKITHOME) is used to refer to the root directory of your ArcGIS Engine install and should be defined once you have sourced arcgis/engine/init_engine.sh (or .csh). For examples of each of these steps, see the template makefiles: Makefile.SolarisQt and Makefile.LinuxQt.
  1. Use the -I compiler option to add some additional include directories:
    • $(AGSDEVKITHOME)/include
    • (Linux) /usr/X11R6/include (or the correct version for your installation)
  2. Use the -L linker option to specify some additional library directories:
    • $(AGSDEVKITHOME)/bin
    • (Linux) /usr/X11R6/lib (or the correct version for your installation)
  3. Use the -l linker option link against some libraries:
    • arcsdk
    • qtctl
    • aoctl
  4. Use the -D compiler option to define the ESRI_UNIX symbol to direct the compiler to read the UNIX support headers from within ArcSDK.h.
  5. Generate Qt compiler and linker arguments with pkg-config:
    • -I$(QTDIR)/include
    • -L$(QTDIR)/lib -lqt

Customizing the templates Makefile.SolarisQt and Makefile.LinuxQt

As a convenience, template makefiles, named Makefile.SolarisQt for Solaris Qt applications and Makefile.LinuxQt for Linux Qt applications, are included with ArcGIS Engine for your use. Makefile.SolarisQt and Makefile.LinuxQt can be found in <install dir>/ArcGIS/developerkit10.0/Samples/ArcObjectsCPP/MakefileTemplates. The following steps highlight the specific areas of those files that must be customized for you to use them in your development process. The modifications shown are based on an application that is written in a single code and a single header file, my_application.cpp and my_application.h, and produces an executable that 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 'qt_sample', to reflect your application name. In this example, the program name is my_application.

        # Set up the program name
        PROGRAM = my_application
        ...
        # Program name updates - source list
        CXXSOURCES = my_application.cpp
        ...
        # Program name updates - objects, dependencies, and compilation commands
        my_application.o: my_application.cpp my_application.h
            $(CXX) $(CXXFLAGS) -c -o my_application.o my_application.cpp
  1. Update the dependencies list for your application. This line was also shown above to illustrate the update of the program name. However, it may also involve adding additional parameters and lists if the application you are writing is broken up into more files. 

        # Program name updates - objects, dependencies, and compilation commands
        my_application.o: my_application.cpp my_application.h
            $(CXX) $(CXXFLAGS) -c -o my_application.o my_application.cpp
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.SolarisQt or Makefile.LinuxQt is ready to compile your application, you can compile from the command line by typing "make -f Makefile.SolarisQt" or "make -f Makefile.LinuxQt", as appropriate.

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 your ArcGIS Engine application, type "make -f Makefile.SolarisQt run" or "make -f Makefile.LinuxQt run", as appropriate.

A Note for Qt version 4

The include paths and libraries change for version 4 of Nokia's Qt toolkit. Replace your include paths with -I$(QT4DIR)/include -I$(QT4DIR)/include/Qt, where QT4DIR reflects either a Makefile macro or an environment variable set to your Qt 4 installation. Replace your library with -lQtCore -lQtGui. While your code for the ArcGIS Engine C++ Qt control widgets remains unchanged from Qt version 3, the code for Qt version 4 in general has changed slightly. Please refer to your Qt version 4 documentation to learn about transitioning your code from Qt version 3.