HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- C++ dynamic shared lib loading
Operating System - HP-UX
1833873
Members
2953
Online
110063
Solutions
Forums
Categories
Company
Local Language
back
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
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
10-21-2002 07:44 AM
10-21-2002 07:44 AM
C++ dynamic shared lib loading
I'm trying to implement dynamic loading of a shared library instead of implicit loading. However, I'm having problems with symbol resolution. Specifically I'm stuck on the constructor and destructor - how to declare myClass* myVar = new myClass() when myClass() is bound late?
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2002 01:14 PM
10-21-2002 01:14 PM
Re: C++ dynamic shared lib loading
This depends on what you are trying to accomplish with dynamic loading. Perhaps you know exactly what the library
will contain but want to do some runtime decision about which of several libraries you want to load in.
It is possible to just make function calls such as constructors even though you don't link with the library. The linker will complain about the unsatisfied references, but it will create a program file anyway. If you compile with 32-bit mode, you need to do a chmod +x a.out after linking because the linker won't make the a.out executable if it is missing symbols. If you compile with 64-bit mode you can link with -Wl,+allowunsat and the linker will warn about unsats but still make an executable a.out. You can run the executable successfully as long as you link with the default "-B deferred" mode and load the library before you make any calls to its function. (You can't have
a direct dependency on a data item because those have to found at program startup.)
You can use a more subtle approach by linking with a shared library that resolves the symbols at link time, but then replace that shared library with a stub at runtime. The stub doesn't have to resolve the same functions that its namesake had at link time. The dld.sl will look for those symbols in any shared library, including ones that you dynamically load later.
The more conventional approach to this is to use only "extern C" functions in a shared library and then use shl_findsym to look up the address of each function that you will call. That would mean that your a.out could not have direct reference to any classes implemented inside the dynamically loaded shared library. You would need to hide class objects behind something like "void *" parameters that you pass in and out of the access functions.
will contain but want to do some runtime decision about which of several libraries you want to load in.
It is possible to just make function calls such as constructors even though you don't link with the library. The linker will complain about the unsatisfied references, but it will create a program file anyway. If you compile with 32-bit mode, you need to do a chmod +x a.out after linking because the linker won't make the a.out executable if it is missing symbols. If you compile with 64-bit mode you can link with -Wl,+allowunsat and the linker will warn about unsats but still make an executable a.out. You can run the executable successfully as long as you link with the default "-B deferred" mode and load the library before you make any calls to its function. (You can't have
a direct dependency on a data item because those have to found at program startup.)
You can use a more subtle approach by linking with a shared library that resolves the symbols at link time, but then replace that shared library with a stub at runtime. The stub doesn't have to resolve the same functions that its namesake had at link time. The dld.sl will look for those symbols in any shared library, including ones that you dynamically load later.
The more conventional approach to this is to use only "extern C" functions in a shared library and then use shl_findsym to look up the address of each function that you will call. That would mean that your a.out could not have direct reference to any classes implemented inside the dynamically loaded shared library. You would need to hide class objects behind something like "void *" parameters that you pass in and out of the access functions.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP