The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
static and shared libraries JamesByars UNIX for Advanced & Expert Users 2 01-13-2008 02:29 PM
debugging shared objects yakari UNIX for Advanced & Expert Users 0 10-03-2006 01:14 PM
How about finding out all objects by owner HAA Shell Programming and Scripting 3 05-29-2006 06:07 AM
Shared Objects Yura UNIX for Advanced & Expert Users 3 09-02-2005 01:25 PM
Shared Objects mrgubbala UNIX for Dummies Questions & Answers 3 03-02-2005 02:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-16-2004
maestro@altiris maestro@altiris is offline
Registered User
  
 

Join Date: May 2004
Posts: 7
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!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0