Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Feb 1997 10:50:18 -0800 (PST)
From:      Sujal Patel <smpatel@prognet.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Static variables in shared libraries
Message-ID:  <Pine.BSF.3.95.970225104655.14413A-100000@sujal.prognet.com>
In-Reply-To: <3.0.1.32.19970225003040.00ff58e4@prognet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 25 Feb 1997, Peter Haight wrote:

> const char* test_3 = "hello";
> const char* test_4 = test_3;
> 
> If I dynamically load this shared library in my program and print the
> variables, I get:
> test_3 = "hello"
> test_4 = 0x0
> 
> What's going on?

The two lines you have written are not handled like C globals.  Because
test_4 isn't a constant, you need to have the C++ global constructor
called when your shared lib is loaded (otherwise test_4 will never be
initialized).

What you need to do is to include /usr/lib/c++rt.o in the link line for
your shared library.  This will include the __init function that will
run your global c++ constructors.


Sujal




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95.970225104655.14413A-100000>