[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ shared libraries on Sun Forte compiler

From: Ulrik Petersen
Subject: C++ shared libraries on Sun Forte compiler
Date: Thu, 28 Nov 2002 16:35:56 +0100 (CET)


libtool is great, but unfortunately it still does not
work equally well on all platforms.  I have problems
with building shared C++ libraries on the Sun Forte CC
compiler, especially when using templates.  There are
severel problems, all of which I will describe below.

The Sun Forte compiler has problems when object files
are moved around, which libtool does by default.  This
is because the Sun Forte compiler stores template
instances in separate files, along with information
about which object files belong with which template
instances.  Thus when object files are moved around
(between $libdir and $objdir), the linker (which
happens to be the compiler) does not know where to
find the template instances, resulting in unresolved
symbols.  There is a FAQ dealing with this at:

Here is a (very dirty) sed script I use in my in order to make libtool work:

s%$show "$mv $output_obj $libobj"%\#%
s%$show "$mv $libobj $obj"%\#%
s%$show "$mv $output_obj $obj"%\#%
s%$show "$mv $libobj $lo_libobj"%\#%
s%$run $mv $output_obj $libobj%test "x" = "x"%
s%$run $mv $libobj $obj%test "x" = "x"%
s%$run $mv $output_obj $obj%test "x" = "x"%
s%$run $mv $libobj $lo_libobj%test "x" = "x"%
s%\*\.lo) libobjs="\$libobjs \$arg"%\*\.lo)
libobjs="\$libobjs \$objdir/\$arg"%

As you can see, this sed script solves three problems:

1) It sets compiler_o_lo to yes, even though
aclocal.m4 believes it should be no.  

2) It removes the lines that mv any object files.

3) It puts $objdir/ in front of all object files when

Also, as detailed in the Sun Forte C++ User's Guide,
one should use CC -xar -o instead of ar and CC -g
instead of ld when linking C++ libraries.  Otherwise,
templates are not instantiated.

Here is the code I use in my to
accomplish this.  ISHOSTSUNCC is a variable I set

if test x$ISHOSTSUNCC = xyes; then
  AR_FLAGS="-xar -o";
  export AR AR_FLAGS LD

dnl Invoke libtool

Of course, one should not use the CC compiler as the
linker/archiver when linking C libraries.  So there
are some language-related complexities involved here.

The Sun Forte C++ User's Guide can be found at:

The relevant sections are: Chapter 7 (especially
7.3.1), Chapter 16 (especially 16.2 and 16.3), Chapter

If you need any other information, please contact me
off-list: address@hidden

Best regards,

Ulrik Petersen
Emdros maintainer, <>

Ulrik Petersen, Denmark

Beskyt din computer mod virus og misbrug! Læs mere i Yahoo! Sikkerhedscenter på

reply via email to

[Prev in Thread] Current Thread [Next in Thread]