Static objects in libraries


 
Thread Tools Search this Thread
Top Forums Programming Static objects in libraries
# 1  
Old 11-16-2004
Static objects in libraries

Hi!

I have the following problem with C++ programs on Unix:

There is a binary executable program called, e.g. Main. It is dynamically linked with two shared libraries: Shared1 and Shared2. Both of these libraries, in turn, are statically linked with a static library called Static. This static library has a static object called StaticObj declared and defined as:

Code:
class MyClass
{
    public:
        static MyClass StaticObj;
};

MyClass MyClass::StaticObj;

Now, when I run the execucable Main, I get into the problem that StaticObj is initialized twice. This means that MyClass constructor is called twice on the same address. The same story happens with the destructors.

It is naturally that such behaviour would not be desired, especially when you deal with some objects that have states. Neither is applicable variant, which makes two independed copies of StaticObj for libraries Shared1 and Shared2 (imagine that StaticObj is a mutex!).

Has anyone run across a similar problem and found a good solution?

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Even the Static cURL Library Isn't Static

I'm writing a program which uses curl to be run on Linux PCs which will be used by a number of different users. I cannot make the users all install curl on their individual machines, so I have tried to link curl in statically, rather than using libcurl.so. I downloaded the source and created a... (8 Replies)
Discussion started by: BrandonShw
8 Replies

2. Programming

Question about what Static Libraries are...

im used to windows dll which gets loaded at runtime, are static libraries the same? the ones i link with -l on gcc? i mean, if my app used libpng for example, and i compiled it to a single ELF executable and took it to another pc that have no libpng on it, will it work? or it will complain... (2 Replies)
Discussion started by: JonhyM
2 Replies

3. Linux

Could static library include static library?

I have some static library(libxxx.a libyyy.a). And I want to generate my library(libzzz.a), libzzz.a will use libxxx.a and libyyy.a I wan't my application only use libzzz.a, (means libzzz.a had include libxxx.a, libyyy.a), how can I do that? Thank you. example: I have zzz.c. I do ... (4 Replies)
Discussion started by: freemagic
4 Replies

4. IP Networking

I need HELP to Set up Coyote Linux router with 1 static IP & 64 internal static IP

hello, i need help on setting my coyote linux, i've working on this for last 5 days, can't get it to work. I've been posting this message to coyote forum, and other linux forum, but haven't get any answer yet. Hope someone here can help me...... please see my attached picture first. ... (0 Replies)
Discussion started by: dlwoaud
0 Replies

5. Programming

Static libraries and fork()

Hi, Let's say there's an application compiled with a static library. So, if the application forks processes, then the static library is copied, also? Or the static library codes are shared between the processes of the application? Thanks in advance. (2 Replies)
Discussion started by: xyzt
2 Replies

6. UNIX for Advanced & Expert Users

static and shared libraries

can someone explain whether my understanding is correct lets suppose we have a program that uses library x. if x is static then the code of x will be part of our program, so if we're going to have 5 executables of our program, then each executable will have x as part of it. Also, x does not... (2 Replies)
Discussion started by: JamesByars
2 Replies

7. UNIX for Advanced & Expert Users

Business Objects on Solaris

Has anyone installed BO on a Solaris 8 server that accesses DB2? I am having a problem the I am filling a file system up but the available precentage remains the same. (1 Reply)
Discussion started by: EdZ
1 Replies

8. UNIX for Advanced & Expert Users

Shared Objects

Hi. Does anyone know by how much a text size of an executable(on ibm) would grow if you link one shared object(library)? Is it a constant number or it depends on a .so that is linked? (3 Replies)
Discussion started by: Yura
3 Replies

9. Programming

Linking with shared objects

hi all ! Do I need all the shared objects to be present while compiling my code which has reference to a only one shared object, which in turn refers to another shared object. for example I want to compile example.c which refers to sample.so sample.so has refrence to anothersample.so do... (2 Replies)
Discussion started by: disclaimer
2 Replies

10. UNIX for Dummies Questions & Answers

Shared Objects

Hi Friends ! I have a library, say libxyz.a. To view all the object files in the archive, i issued the command : ar -t libxyz.a which displayed all the object files it contains. Now, I would like to know the functions in each object file. Is there any such command that displays... (3 Replies)
Discussion started by: mrgubbala
3 Replies
Login or Register to Ask a Question
COMPAT_OSF1(8)						    BSD System Manager's Manual 					    COMPAT_OSF1(8)

NAME
compat_osf1 -- setup procedure for running OSF/1 binaries DESCRIPTION
NetBSD supports running OSF/1 (a.k.a Digital Unix, a.k.a. Tru64) binaries on NetBSD/alpha systems. Most programs should work, including the ones that use the shared object libraries. Programs that make direct MACH system calls will not work. The OSF/1 compatibility feature is active for kernels compiled with the COMPAT_OSF1 option enabled (see options(4)). To run dynamically linked programs, you will need the OSF/1 shared libraries, runtime linker, and certain configuration files found in /etc. These are installed in a ``shadow root'' directory called /emul/osf1. Any file operations done by OSF/1 programs run under NetBSD will look in this directory first, and fall back to the file system proper. So, if an OSF/1 program opens /etc/svc.conf, NetBSD will first try to open /emul/osf1/etc/svc.conf, and if that file does not exist it will then try /etc/svc.conf. Shared libraries and configuration specific to OSF/1 should be installed in the shadow tree. Setting up /emul/osf1 The simple technique is to install pkgsrc/emulators/osf1_lib. (You may also want to install pkgsrc/www/navigator and/or pkgsrc/www/communi- cator.) Alternatively, if you have access to an OSF/1 machine and if the licensing details permit, you can copy the contents of: /shlib /usr/shlib /etc/sia /usr/lib/X11/locale (The latter is required to run Netscape Navigator or Communicator.) Also copy /etc/svc.conf /usr/ccs/lib/cmplrs/otabase/libots.so /sbin/loader Or, simply NFS mount the appropriate directories under /emul/osf1. SEE ALSO
config(1), options(4) BUGS
Your hostname(1) must contain a dot or your resolv.conf(5) must contain a search line. Without one of those, the OSF/1 resolver will die and no hostname resolution will be possible. Certain values in /emul/osf1/etc/svc.conf can cause programs to fail with ``Bad system call''. Pathnames pointed to by symbolic links are not looked up in the shadow root when running an OSF/1 executable. This is not consistent. BSD
November 4, 1999 BSD