This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

troubles with shared library creation


    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.
	

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]