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;
m.h:Quote:}
#include <map>
class M
{
public:
M();
void use ( char c );
private:
typedef std::map<char, int> Table;
Table t_;
m.cxx:Quote:};
#include "m.h"
M::M()
{
t_['x'] = 15;
void M::use ( char c )Quote:}
{
t_[c]++;
Linking the objects works fine:Quote:}
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> >
td::pair<const char,int>,__rwstd::__select1st<std::pair<constQuote:>::iterator,bool>__rwstd::__rb_tree<char,s
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.