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
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 the template makefiles provided with ArcGIS Engine. Makefile.Solaris provides a starting point for Solaris command-line applications, and Makefile.Linux will get you started with Linux command-line applications. Refer to the next section for details on these sample files.
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.Solaris and Makefile.Linux.
- Use the -I compiler option to add some additional include directories:
- $(AGSDEVKITHOME)/include
- (Linux) /usr/X11R6/include (or the correct version for your installation)
- Use the -L linker option to specify some additional library directories:
- $(AGSDEVKITHOME)/bin
- (Linux) /usr/X11R6/lib (or the correct version for your installation)
- Use the -l linker option link against the arcsdk library.
- 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.Solaris and Makefile.Linux
As a convenience, template makefiles, named Makefile.Solaris for Solaris command-line applications and Makefile.Linux for Linux command-line applications, are included with ArcGIS Engine for your use. Makefile.Solaris and Makefile.Linux can be found in <install dir>/ArcGIS/DeveloperKit10.0/Samples/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.
- Throughout the makefile, update the program name, currently 'basic_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 - 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.Solaris or Makefile.Linux is ready to compile your application, you can compile from the command line by typing "make -f Makefile.Solaris" or "make -f Makefile.Linux", 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 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 = /mycomputer/data/inputfile
...
# Setting up a run target
run:
$(PROGRAM) $(INPUT)
# Setting up the program argument
INPUT = /mycomputer/data/inputfile
...
# Setting up a run target
run:
$(PROGRAM) $(INPUT)
Once Makefile.Solaris or Makefile.Linux is ready for use with your application, you will be able to run from the command line by typing "make -f Makefile.Solaris run" or "make -f Makefile.Linux run", as appropriate.