This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
troubles with shared library creation
- To: gcc-help at gcc dot gnu dot org
- Subject: troubles with shared library creation
- From: "Alexander Darovsky" <a dot darovskikh at compassplus dot ru>
- Date: Fri, 26 Jan 2001 14:58:40 +0500 (YEKT)
- Reply-to: a dot darovskikh at compassplus dot ru
This problem occured when I tried to
create several shared libraries with identical symbols there:
// ------------ lib1.cpp: ---------
#include <iostream.h>
#include "common.h"
class A {
public:
A() { cout << "lib1.A()" << endl; func(); Common c; func2(c); }
void func() {cout << "lib1.A::func()" << endl;}
Common func2( Common ){}
};
static A a;
// ------------ lib2.cpp: ---------
#include <iostream.h>
#include "common.h"
class A {
public:
A() { cout << "lib2.A()" << endl; }
void func() {cout << "lib2.A::func()" << endl;}
};
static A a;
Common::Common() {
cout << "Common::Common() from lib2" << endl;
}
// ---------- lib3.cpp -----------
#include <iostream.h>
#include "common.h"
class A {
public:
A() { cout << "lib3.A()" << endl; }
void func() {cout << "lib3.A::func()" << endl;}
};
static A a;
Common::Common() {
cout << "Common::Common() from lib3" << endl;
}
// ---- common.h
class Common {
public:
Common();
};
and there's one else file "main.cpp" containing an empty main().
When I link them just using -shared key:
liblib1.so : lib1.cpp
c++ lib1.cpp -L. -shared -o liblib1.so
, I have two objects from lib2 created instead of one from lib1.cpp
and another from lib2.cpp. -Bsymbolic option to linker also doesn't
give good result, because it doesn't allow undefined Common::Common()
from lib1. The only way I've found is to use VERSION control in "ld".
Or, as an alternative, --export-symlist for libtool. But it requires
an additional file .sym and rather sophisticated script to generate
it. May be there's a more simple way, like __export in M$?
With great hope on help, Alexander Darovsky.