- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- C++ shared library loading not calling constructor...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-27-2005 03:15 PM
тАО01-27-2005 03:15 PM
C++ shared library loading not calling constructor for global and static const members not being set
We changed the code to have the global initialized with the first call into the main entry point/C function in the shared object. Then we noticed a related problem, all our static const members that we initialized with a value are not getting initialized, almost as if these const members are not getting setup either when the shared object loads.
We are using the /usr/bin/ld linker, the commercial ansic and aCC compilers on HP-UX PA-RISC 11i v1 that is brand new with the GOLDBUNDLE 11i from June 04 and with lots of new patches.
What are we doing wrong. We tried building the shared object with the linker directly and with the ansic complier and then with the aCC compiler to call the linker. No difference. We did this because of different info in different locations in documentation about how to do it.
Help!
- Tags:
- shlib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-27-2005 06:17 PM
тАО01-27-2005 06:17 PM
Re: C++ shared library loading not calling constructor for global and static const members not being set
is it possible to reduce the problem to a minimal piece of code and compile/link line ? for example, this script shows you what works and what does not:
-----
[12:39:35] $ cat con.tst
cat > 1.h << \!
#include
class A {
private:
int a;
public:
A (int i) { a=i; printf("constructor called with %d\n", i); }
~A () { printf("destructor called for %d\n", a); }
};
!
cat > 1.c << \!
#include "1.h"
static A a(5);
static A *b;
extern "C" void function () { puts("function called"); }
#ifdef USE_INITFINI
extern "C" void init () { a=A(5); }
extern "C" void fini () { (&a)->~A(); }
#endif
!
cat > 2.c << \!
#include
#include
int main () {
void *dl;
void (*func)();
puts("before dlopen");
dl = dlopen("lib1.sl", RTLD_LAZY);
puts("after dlopen");
if (dl == NULL)
return 1;
func = (void(*)())dlsym (dl, "function");
if (func != NULL) {
(*func)();
}
puts("before dlclose");
dlclose(dl);
puts("after dlclose");
return 0;
}
!
aCC 1.c -b +z -o lib1.sl
aCC 2.c
echo
echo ---- compiled and linked with aCC ----
./a.out
aCC +z -c 1.c
ld -b 1.o -o lib1.sl
echo
echo ---- linked plain with ld ----
./a.out
aCC +z -DUSE_INITFINI -c 1.c
ld -b 1.o +init init +fini fini -o lib1.sl
echo
echo ---- linked with ld, with init and fini ----
./a.out
echo
----
in my environment:
----
[12:39:35] $ ksh con.tst
---- compiled and linked with aCC ----
before dlopen
constructor called with 5
after dlopen
function called
before dlclose
destructor called for 5
after dlclose
---- linked plain with ld ----
before dlopen
after dlopen
function called
before dlclose
after dlclose
---- linked with ld, with init and fini ----
before dlopen
constructor called with 5
destructor called for 5
after dlopen
function called
before dlclose
destructor called for 5
after dlclose
[12:39:39] $ aCC -V
aCC: HP ANSI C++ B3910B A.03.55
[12:40:57] $ /usr/sbin/swlist | grep -i linker
PHSS_19866 1.0 ld(1) and linker tools cumulative patch
PHSS_28433 1.0 linker startup code / SLLIC ELF support
PHSS_30969 1.0 ld(1) and linker tools cumulative patch
----
--
ranga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2005 03:13 AM
тАО01-28-2005 03:13 AM
Re: C++ shared library loading not calling constructor for global and static const members not being set
Can I link C libraries and exes with aCC even though they are straight ansi C?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-28-2005 03:38 AM
тАО01-28-2005 03:38 AM
Re: C++ shared library loading not calling constructor for global and static const members not being set
It says:
/usr/ccs/bin/ld: Can't find library: "ibase"
The -L../../hpxbin where the shared obj is located is in there and the -libase is after it.
Is there a problem with aCC calling the linker to make an EXE with resolving the locations of the shared objects?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-30-2005 10:38 PM
тАО01-30-2005 10:38 PM
Re: C++ shared library loading not calling constructor for global and static const members not being set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2005 02:33 AM
тАО01-31-2005 02:33 AM
Re: C++ shared library loading not calling constructor for global and static const members not being set
The problem I was having with getting the compiler to call the linker and resolve linked in libraries uisng the -L path option was because of a TYPO, +AA instead of -AA.
Also the problem is that the C shared object that loads other shared objects that can be C or C++ has to be linked with using aCC to call the linker for it to properly call the global's constructors and so forth.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2005 02:34 AM
тАО01-31-2005 02:34 AM