Two shared object with same class name

R

rinku24

We have two C++ libraries (Unix Shared objects) with the same class
name and no namespace. Is there any way to load both the libraries and
selectivly create the instance of the class from different library?

e.g. We have class Process in libABC.so and libXYZ.so.

Can I instantiate object of class Process from libABC.so or libXYZ.so
by specifying symbol name or some other way??

I know can do that for global function using dlsym function call.
 
V

Victor Bazarov

We have two C++ libraries (Unix Shared objects) with the same class
name and no namespace. Is there any way to load both the libraries and
selectivly create the instance of the class from different library?

e.g. We have class Process in libABC.so and libXYZ.so.

Can I instantiate object of class Process from libABC.so or libXYZ.so
by specifying symbol name or some other way??

<offtopic reason="OS-specific">
You're going to be better off talking to the makers of these libraries
and getting them to put their classes in respective namespaces. In the
mean time you could wrap those libraries in your own classes, something
like

class ABC_Process {
... // same functionality as Process from ABC, implemented in terms
// of the Process from ABC
};
ABC_Process* ABC_Factory(...) { ... }

class XYZ_Process {
... // same functionality as Process from XYZ, implemented in terms
// of the Process from XYZ
};
XYZ_Process* XYZ_Factory(...) { ... }

The factories will have to be placed in their own dynamic libraries,
which, in turn, will load the libABC.so and libXYZ.so, respectively. IOW,
your main application should have no direct contact with libABC or libXYZ.
</offtopic>

For more information and suggestions on how to handle name clashes due to
shared objects exporting the same symbols, ask in a newsgroup dealing with
your OS -- shared objects, dynamic libraries, and the such, are off-topic.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,652
Latest member
Campbellamy

Latest Threads

Top