Problem linking when using C++ library in a library on Solaris

Problem linking when using C++ library in a library on Solaris

Post by Andreas Pag » Fri, 02 May 2003 19:40:45



I've got a strange linking problem that I've been struggling with and
I hope someone can tell me what's going on and how to fix it.

I've got a few classes that I compile into a static library, but when
I link my executable with this library, the linker complains about
undefined symbols.  These symbols look like they come from the C++
library.  The strange thing is, everything works fine when I link
using the object files in the library.

I'm using a Sun Ultra-250 running Solaris 2.8, using the Sun Workshop
version 6 C++ compiler.  Here's sample code:

driver.cxx:

#include "m.h"

int main()
{
    M m;

    m.use ( 'r' );

    return 0;

Quote:}

m.h:

#include <map>

class M
{
public:
    M();

    void use ( char c );

private:
    typedef std::map<char, int> Table;

    Table t_;

Quote:};

m.cxx:

#include "m.h"

M::M()
{
    t_['x'] = 15;

Quote:}

void M::use ( char c )
{
    t_[c]++;

Quote:}

Linking the objects works fine:

CC -c driver.cxx
CC -c m.cxx
CC -o driver driver.o m.o

But if I now create a library and use that I get the undefined error:

ar -r m.a m.o
ar: creating m.a
CC -o driver driver.o m.a
Undefined                       first referenced
 symbol                             in file
std::pair<__rwstd::__rb_tree<char,std::pair<const
char,int>,__rwstd::__select1st<std::pair<const char,int>,
char>,std::less<char>,std::allocator<std::pair<const char,int> >

Quote:>::iterator,bool>__rwstd::__rb_tree<char,s

td::pair<const char,int>,__rwstd::__select1st<std::pair<const
char,int>,char>,std::less<char>,std::allocato
r<std::pair<const char,int> > >::insert(const std::pair<const
char,int>&) m.a(m.o)
ld: fatal: Symbol referencing errors. No output written to driver

What's going on, and how can I fix it?

Thanks in advance for any help,

Andreas.

 
 
 

Problem linking when using C++ library in a library on Solaris

Post by Paul Pluzhniko » Sat, 03 May 2003 00:03:11



> The strange thing is, everything works fine when I link
> using the object files in the library.

What's happening here is that your 'm.a' is incomplete --
it is missing template instantiation objects (stuff from
SunWS_cache) ...

Quote:> ar -r m.a m.o

Don't do that. Use "CC -xar -o m.a m.o" instead.

Cheers,
--
In order to understand recursion you must first understand recursion.

 
 
 

Problem linking when using C++ library in a library on Solaris

Post by Andreas Pag » Sun, 04 May 2003 01:22:58



> > ar -r m.a m.o

> Don't do that. Use "CC -xar -o m.a m.o" instead.

Thanks very much, this has worked perfectly.  It's in the CC man page,
if you know to look there!  I went through man pages for ar and ld,
but not CC...

Andreas.

 
 
 

1. Dynamical Link Problem on Solaris using CC (Shared Libraries)

Hi There,

Howto properly link with shared Libraries?

I've got the following error message:
 CC -norunpath -g -PIC -mt
-L/opt/local/share/VERSANT/5.2.2.2/5.2.2/sun4/lib/sun.4.0.odmg
-L/opt/local/share/VERSANT/5.2.2.2/5.2.2/sun4/lib
-L/opt/local/share/VBROKER/its_1.0/lib
-L/pro/tnms/sem_eli/boss/ev/lib
-L/pro/tnms/sem_eli/base/lib/sol26
-L/pro/tnms/sem_eli/derived/sol26/lib
-L/opt/local/rogue/lib -o
/pro/tnms/sem_eli/boss/ev/bin/evdbmngr.bin
evdatabaseeventmanager.o -lev -lrs -lom -lpf -lsf
-lopt -lmc -leh -lcfh -ltrc -lmt -lac -lbst -lfsm
-lxa -lxacxx -loscfe -lcxxcls -lvcoll -lorb_r
-lname_r -lits_support -ltls7d -lthr7d -lstd15d
-nolib -Bstatic -lsunmath_mt -lm -lC -lw -lcx
-Bdynamic -lposix4 -lpthread -lc -lsocket -lnsl

ild: (argument error) can't find library arguments
:: -lev -lrs -lom -lpf -lsf -lopt -lmc -leh -lcfh
-ltrc -lmt -lac -lbst -lfsm

Even if libev.so exists in
/pro/tnms/sem_eli/boss/ev/lib which is specified
with -L, so -lev should work?

Who can help me, where's the problem?

Thank You
Regards
Marc

(my email address is

DELETE_THIS_ and _AND_THIS - sorry for the
inconvenience, but there
are spammers seeking newsgroups for email
adresses)

Opinions expressed in newsgroups are alwaye mine,
not correlated to
those of my company.

2. Modeline problems

3. Problems linking static library on executable and static library

4. Redhat 7.3 hangs on shutdown - drives not unmounted

5. GCC problems: C++ library linking doesn't work

6. KDE is unreadable -- funky transparent windows

7. Problem linking C++ library with C program

8. digital pictures -> web site

9. Using Solaris and GNU C++ libraries together

10. linking with static libraries using solaris CC

11. library compatibility between c and c++ in ncurses cdk library

12. Problems in creating and using C++ shared libraries...

13. AIX Linking problem using debug malloc library