Re: static class members, shared libs and other vegetables
- From: Paul Pluzhnikov <ppluzhnikov-nsp@xxxxxxxxxxx>
- Date: Mon, 26 Mar 2007 18:39:13 -0700
"Maor Avni" <maor.avni@xxxxxxxxx> writes:
I'm trying to create a quick-and-dirty solution to a problem one of....
our customer requires: one of the libs in our product needs to be
instantiated two times. The problem is that it contains many static
members.
Our first solution was to compile all libraries to a second set of
libraries, and load the two sets separately. This solution worked on
Windows, and we successful created two instances of every static
member in the system.
The solution doesn't work on Linux, as static members for some reason
are shared across the libraries, although the libraries are loaded
dynamically at the start of the program.
This is *expected*.
Win32 uses a "DLL is a self-contained entity; nothing should change
its behaviour once it has been built" model.
Most UNIXes use a "linking against DSO is just like linking against
archive; you should be able to override any symbols in it with your
own" model. The "first instance" of your DSO overrides symbols in
the "second instance".
One way to solve this issue is, naturally, putting the code behind one
namespace, compiling it, changing the namespace and compiling the code
again. Unfortunately, this solution is too costly to implement since
the project contains a large number of files that should be changed.
In addition, this solution will be disposed of in the near future as
the static variables are removed.
Is there a quicker and dirtier way to solve this issue? Maybe some
script or switch to compile all code under a single namespace.
Probably. You didn't specify whether client code depends on any of
the static data being "exported" from the DSO, but given that
"two DLL solution" worked on Win32, the answer is probably no.
In that case, you can hide (make local) all the static data inside
the DSO with a linker script, and achieve behaviour that is exactly
equivalent to what you have on Win32.
Try "info ld" -> Scripts -> VERSION
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
.
- Follow-Ups:
- References:
- static class members, shared libs and other vegetables
- From: Maor Avni
- static class members, shared libs and other vegetables
- Prev by Date: static class members, shared libs and other vegetables
- Next by Date: New Linux kernel written in BASIC to be released in 5 days.
- Previous by thread: static class members, shared libs and other vegetables
- Next by thread: Re: static class members, shared libs and other vegetables
- Index(es):
Relevant Pages
|
|