Compiling and linking

This section describes how to compile and link C and C++ client programs. Compiling and linking a client program with a SOM class is done in one of two ways, depending on how the class is packaged.

Note: If you are building an application that uses a combination of C and C++ compiled object modules, then the C++ linker must be used to link them.

If the class is not packaged as a library (that is, the client program has the implementation source code for the class, as in the examples given in the SOM IDL tutorial), then the client program can be compiled together with the class implementation file as follows. (This assumes that the client program and the class are both implemented in the same language, C or C++. If this is not the case, then each module must be compiled separately to produce an object file and the resulting object files linked together to form an executable.)

In the following examples, the environment variable SOMBASE refers to the directory in which SOM has been installed. The examples also assume that the header files and the import library for the "Hello" class reside in the "include" and "lib" directories where SOM has been installed. If this is not the case, additional path information should be supplied for these files. For client program "main" and class "Hello":

Under AIX, for C programmers:

   > xlc -I. -I$SOMBASE/include main.c hello.c -L$SOMBASE/lib -lsomtk \
         -o main

Under AIX, for C++ programmers:

   > xlC -I. -I$SOMBASE/include main.C hello.C -L$SOMBASE/lib -lsomtk \
         -o main

Under OS/2, for C programmers:

   > set LIB=%SOMBASE%\lib;%LIB%
   > icc -I. -I%SOMBASE%\include main.c hello.c somtk.lib

Under OS/2, for C++ programmers:

   > set LIB=%SOMBASE%\lib;%LIB%
   > icc -I. -I%SOMBASE%\include main.cpp hello.cpp somtk.lib

If the class is packaged as a class library, then the client program, "main", is compiled as above, except that the class implementation file is not part of the compilation. Instead, the "import library" provided with the class library is used to resolve the symbolic references that appear in "main". For example, to compile the C client program "main.c" that uses class "Hello":

Under AIX:

   > xlc -I. -I$SOMBASE/include main.c -lc -L$SOMBASE/lib -lsomtk \
         -lhello -o main

Under OS/2:

   > set LIB=%SOMBASE%\lib;%LIB%
   > icc -I. -I%SOMBASE%\include main.c somtk.lib hello.lib


[Back: Referring to class objects]
[Next: Language-neutral Methods and Functions]