LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-08-2009, 07:03 AM   #1
adevi003
LQ Newbie
 
Registered: Oct 2009
Posts: 8

Rep: Reputation: 0
Question Shared object constructor not called when library loaded


OS Version: Linux red hat EL5
g++ version: 4.1.1
ld version: 2.17.50.0.6-2.el5

I have a shared library and a unit test executable that depends on the shared library. Both compile and link without warning or error. The g++ options for the shared library are:

compile: -fPIC -Wall -Wno-unused-function -fno-strict-aliasing -g -O0
link: -shared -lstdc++

The options for the unit test executable are the same without the -shared.

In the shared library I have designated a constructor function as so:

Code:
#define ZENCORE_CONSTRUCTOR __attribute__ ((constructor))
#define ZENCORE_DESTRUCTOR __attribute__ ((destructor))

void ZENCORE_CONSTRUCTOR ZencoreInit(void);

void ZENCORE_DESTRUCTOR ZencoreCleanup(void);
However, when I run the test executable, the ZencoreInit function is not called. Rather, what I get in the stack trace is this:

#1 0x002a89b1 in global constructors keyed to _ZN3zen12g_UUIDRandomE() at zenuuiinitialize.cpp: 93
#2 0x002a8b46 in __do_global_ctors_aux() from /usr/local/lib/ngs/libzencored.so
#3 0x00234c2d in _init() from /usr/local/lib/ngs/libzencored.so
#4 0x00886f03 in call _init() from /lib/ld-linux.so.2
#5 0x00887013 in _dl_init_internal() from /lib/ld-linux.so.2
#6 0x0087984f in _dl_start_user() from /lib/ld-linux.so.2

I compiled a test program with a similar structure and with the same compile/link options and it worked just fine. Also, another shared library that the unit test executable depends on loads the construction function correctly.

I am at a loss and appreciate any help or ideas.
Cheers
A
 
Old 10-09-2009, 12:32 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I assume you're linking with ld because you use -lstdc++. You should link with g++ instead.
Kevin Barry

Last edited by ta0kira; 10-09-2009 at 12:35 PM.
 
Old 10-12-2009, 04:51 AM   #3
adevi003
LQ Newbie
 
Registered: Oct 2009
Posts: 8

Original Poster
Rep: Reputation: 0
I'm using g++ to link. The -lstdc++ had no effect as it functions (or doesn't) the same with and without it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shared library : libfg.so: cannot open shared object file error 40 x_gaurav Programming 2 06-28-2009 06:29 AM
unable to step through function in shared object library using gdb markhod Programming 2 01-03-2009 02:00 AM
Stopped due to shared library event - Failed to read a valid object file... tatchan Programming 3 01-16-2007 01:13 PM
Shared object library that uses another shared object library Nightfox Programming 1 02-15-2006 10:00 PM
shared object library won't load (libstdc++) sleepylight Linux - General 4 04-27-2004 04:24 PM


All times are GMT -5. The time now is 08:56 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration