How to eliminate duplicate symbols from the Rogue Wave C++ libraries
ENV: (AIX 3.2.5, CSet++ version 2) and (AIX 4, CSet++ version 3)
Rogue Wave Tools.h++ Foundation Class library for C++
Programming version 6.
Rogue Wave Math.h++ C++ Class Library for Developing
Numberical Applications version 5.
DESC: When linking a C++ program that uses Rogue Wave templates
classes I am receiving duplicate symbols for the Rogue Wave
template class member functions. WHY?
Determining the answer to this question requires an understanding of
how the user's source code is organized. This answer assumes that the
user of the Rogue Wave C++ template classes has NOT created any
shared libraries themselves that contain functions that instantiate
C++ template classes.
There are basically four steps in eliminating
duplicate symbols related to C++ template classes.
NOTE: This assumes that only a program is being built that links
with the Rogue Wave shared libraries and NO shared libraries
containing C++ template classes are being built by the programmer.
When building shared libraries that instantiate C++ templates
duplicate symbols may be present during linking and it may NOT
be possible to eliminate ALL of the duplicate symbols.
1) First understand the default behavior of the xlC compiler.
2) Second determine/verify how the Rogue Wave source code was
configured and compiled on the system.
3) Third possibly reconfigure, recompile, and rebuild the
Rogue Wave shared libraries.
4) Then recompile user's source and relink with the Rogue Wave
1) UNDERSTANDING THE DEFAULT BEHAVIOR OF THE XLC COMPILER WITH
RESPECT TO C++ TEMPLATE GENEARTION
There are two ways that C++ template classes can be instantiated
by the xlC compiler on AIX.
C++ template classes may be instantiated at COMPILE time or at
LINK time. The way the you control which of the two instantiation
methods are used is based on how you organize your source code
and not directly by compiler options.
COMPILE TIME: Any time a C++ source file has both the C++
template class declarations and function definitions visible
to a compilation unit (i.e. file.C) and the source code in the
file declares a variable of that C++ template class
type, then C++ Template class functions will be generated
in the object module (file.o) by the compiler.
NOTE: For example if you instantiate the same template class
with 5 different data types in each of 100 .C files then
let say also that there were 20 member functions in the class
then using COMPILE time template class instantiation would
result in (20 functions)*(5 data types)*(100 files) would
produce a total of 10,000 symbols. This ultimately results
in oversize executables and long compile/link times. This
case would be idea for using link time instantiation. Using
link time template instantiation would result in
(20 functions) * (5 data types) = 100 symbols and would be
placed in a separate .o file in the subdirectory called
tempinc that would automatically be created.
LINK TIME: Any time a C++ source file has only the C++
template class declarations which were \#include from
another file (ie .h file) and there is a corresponding
.c file in the include directory where the .h file exists
and if the source file (file.C) declares a variable to
be of the C++ template class type, then link time template
generation (automatic) will be used. By default a tempinc
directory will be created in the current working directory.
The "tempinc" directory may be changed by using the
-qtempinc compile/link option.
A .C file will be created in that directory. When a C++
program is linked with the xlC command and a tempinc directory
is found any .C files in that directory will first be compiled
and then the .o files will be added to the link line after all
user specified libraries. NOTE: Using the -v (verbose)
option on a compile/link line will indicate this.
A more in-depth discussion of this topic is available in the
IBM C Set ++ for AIX User' Guide Version 3 Release 1 in Chapter 14.
2) DETERMINING HOW THE ROGUE WAVE C++ CLASS LIBRARIES ARE
CONFIGURED ON AIX
The rogue wave product can be installed in any directory.
This directory must be obtained from the person who installed
the rogue wave product. HINT: You may determine this from the
by typing make -n and check the output for any -I "directory"
that are being used in a compile or link line.
cd "rogue wave base install directory"
grep RW_COMPILE_INSTANTIATE compiler.h
There should be numerous lines. If the RW_COMPILE_INSTANTIATE
macro is defined (typically equal to 1) then assuming that
compiler.h file was used (and not modified) when the
Rogue wave libraries were built, then the RW C++ classes were
configured for compile time instantiation.
Also do a ls -la *.c
If there are no .c files linked to the .cc files then
this is another indication that the Rogue Wave C++
template classes were built to use compile time template
On the other hand if the RW_COMPILE_INSTANTIATE macro
in the compiler.h file is not defined (either commented out
or defined to be zero and there are .c files that are linked
to the corresponding .cc files in the rw include directory,
then the Rogue Wave C++ template classes are properly configured
for link time or (Automatic) template generation on AIX.
3) RECONFIGURING THE ROGUE WAVE C++ CLASS LIBRARY
To change the C++ template instantiation method that the
Rogue Wave libraries use, run the config script in the Rogue Wave
A. cd "rogue wave base install directory"
B. vi ./rw/config.data
for COMPILE time instantiation verify that the line
for LINK time instantiation verify that the line
C. save file with desired line.
NOTE: This will create symbolic links .c to .cc files in the
rw directory. The .c files by default is used by the
xlC compiler to obtain the template class function definitions.
E. Rebuild the Rogue Wave libraries
i.e for the general tools classes
Repeat tasks in step E for each of the rogue wave
C++ class library products. For example, in the case of the
math library substitute mathsrc for toolsrc.
4)RECOMPILE THE USER PROGRAM AND RELINK TO THE RECOMPILED ROGUE WAVE
Support Line: How to eliminate duplicate symbols from the Rogue Wave C++ libraries ITEM: CK7583L
Dated: February 1997 Category: N/A
This HTML file was generated 99/06/24~13:30:17
Comments or suggestions?