Developing with make and Motif using the Solaris/Linux 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/engine/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++ Motif application is exactly like setting up an ArcGIS Engine C++ application -- there are only a few additional libraries to add to the makefile. For those of you familiar with ArcGIS Engine C++ programming, you will only need to add motifctl, aoctl, Xm, Xt, and X11 as libraries to link against (that is, add them with the -l flag, as shown in Step 3 below). 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.SolarisMotif provides a starting point for Solaris Motif applications, and Makefile.LinuxMotif will get you started with Linux Motif 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.SolarisMotif and Makefile.LinuxMotif.
  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:
    • (Linux) pthread
    • Xm
    • Xt
    • X11
    • arcsdk
    • motifctl
    • 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.

Customizing the templates Makefile.SolarisMotif and Makefile.LinuxMotif

As a convenience, template makefiles, named Makefile.SolarisMotif for Solaris Motif applications and Makefile.LinuxMotif for Linux Motif applications, are included with ArcGIS Engine for your use. Makefile.SolarisMotif and Makefile.LinuxMotif 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 'motif_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.SolarisMotif or Makefile.LinuxMotif is ready to compile your application, you can compile from the command line by typing "make -f Makefile.SolarisMotif" or "make -f Makefile.LinuxMotif", 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.SolarisMotif run" or "make -f Makefile.LinuxMotif run", as appropriate.