Compiling and Linking


After writing a user-defined program, use the rtlink shell script to link it with the necessary SmartSockets libraries. The following sections present some examples of using the rtlink script to link the program stored in files myprog.cxx and extfunc.cxx.

On UNIX

These examples represent two methods of invoking the rtlink script on UNIX. In the first example, the compiling and linking steps are executed separately. In the second, they are combined into one step. Both examples use the -o flag to explicitly name the executable, and the -O flag to enable compiler and SmartSockets optimization. rtlink by default uses the cc command to compile and link, but you can override this either by using the CC environment variable (see Using a Different Compiler) or by using the rtlink -cxx flag. Specifying the -cxx flag tells rtlink to use the native C++ compiler (for example, on a Solaris platform the compiler is named CC, on AIX xlC, on Digital UNIX cxx, and so on) and adds the SmartSockets C++ class library to the list of libraries to be linked into the executable. For more information on compiling and linking, see the detailed description of rtlink in the TIBCO SmartSockets Utilities reference.

//  Separate compiles followed by a separate link    
$ CC -O -I$RTHOME/include/$RTARCH -c myprog.cxx  
$ CC -O -I$RTHOME/include/$RTARCH -c extfunc.cxx  
$ rtlink -cxx -O myprog.o extfunc.o -o myprog.x 
 
//  Combined compiles and link    
$ rtlink -cxx -O myprog.cxx extfunc.cxx -o myprog.x 

Using a Different Compiler

By default, rtlink uses the cc command to compile and link files. If the -cxx flag is used, rtlink uses a native C++ compiler to compile and link files. If the CC environment variable is set, rtlink uses it to determine the command to invoke. To use another compiler, set the environment variable to the compiler you wish to use. This example uses the GNU C++ compiler:

$ env CC=g++ rtlink -O myprog.C extfunc.C -o myprog.x 

Do not set the CC environment variable to rtlink because this setting causes rtlink to call itself over and over.

Using Make

If you are using the make utility to control and execute your compilations, you can instead set the CC variable in your makefile and make automatically sets the CC environment variable each time it runs a command. Here is an example of setting CC from a makefile to use the GNU C++ compiler:

CC = g++ 
CFLAGS = -O -I$(RTHOME)/include/$(RTARCH) 
OBJECTS = myprog.o extfunc.o 
 
myprog.x: $(OBJECTS) 
        rtlink -cxx $(OBJECTS) -o $@ 

If you are using GNU make, this may be needed instead in your makefile or GNUmakefile:

export CC = g++ 
CFLAGS = -O -I$(RTHOME)/include/$(RTARCH) 
OBJECTS = myprog.o extfunc.o 
 
myprog.x: $(OBJECTS) 
        rtlink -cxx $(OBJECTS) -o $@ 

On OpenVMS

On OpenVMS, the rtlink syntax is similar to UNIX, except you cannot combine the compilation and link steps. These steps must be explicitly invoked. The next example uses the /executable qualifier to explicitly name the executable. For more information on compiling and linking, see the detailed description of rtlink in the TIBCO SmartSockets Utilities reference.

//  Separate compiles followed by a separate link    
$ cxx/optimize myprog.c    
$ cxx/optimize extfunc.c   
$ rtlink -cxx /executable=myprog.exe myprog.obj extfunc.obj 

The compilations create object files named myprog.obj and extfunc.obj. rtlink creates an executable named myprog.exe.

On Windows

On Windows, compiling and linking is usually accomplished within the Visual C++ Developer Studio environment. There is no rtlink script on Windows. There are several example Visual C++ makefiles in %RTHOME%\examples\cxxipc that you can use as a starting point for your application executables.


TIBCO SmartSockets™ cxxipc Class Library
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com