From owner-freebsd-hackers Tue Feb 25 10:50:16 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id KAA08182 for hackers-outgoing; Tue, 25 Feb 1997 10:50:16 -0800 (PST) Received: from sujal.prognet.com (sujal.prognet.com [204.255.154.231]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id KAA08171 for ; Tue, 25 Feb 1997 10:50:13 -0800 (PST) Received: from localhost (smpatel@localhost) by sujal.prognet.com (8.8.4/8.8.4) with SMTP id KAA17870 for ; Tue, 25 Feb 1997 10:50:18 -0800 (PST) X-Authentication-Warning: sujal.prognet.com: smpatel owned process doing -bs Date: Tue, 25 Feb 1997 10:50:18 -0800 (PST) From: Sujal Patel To: freebsd-hackers@freebsd.org Subject: Re: Static variables in shared libraries In-Reply-To: <3.0.1.32.19970225003040.00ff58e4@prognet.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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