Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 285733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:34:23+00:00 2026-05-12T05:34:23+00:00

I have an application a part of which uses shared libraries. These libraries are

  • 0

I have an application a part of which uses shared libraries. These libraries are linked at compile time.

At Runtime the loader expects the shared object to be in the LD_LIBRARY_PATH , if not found the entire application crashes with error “unable to load shared libraries”.Note that there is no guarantee that client would be having the library, in that case I want the application to leave a suitable error message also the independent part should work correctly.

For this purpose I am using dlsym() and dlopen() to use the API in the shared library. The problem with this is if I have a lot of functions in the API, i have to access them Individually using dlsym() and ptrs which in my case are leading to memory corruption and code crashes.

Are there any alternatives for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:34:23+00:00Added an answer on May 12, 2026 at 5:34 am

    The common solution to your problem is to declare a table of function pointers, to do a single dlsym() to find it, and then call all the other functions through a pointer to that table. Example (untested):

    // libfoo.h
    struct APIs {
       void  (*api1)(void);
       void *(*api2)(int);
       long  (*api3)(int, void *);
    };
    
    // libfoo.cc
    void fn1(void) { ... }
    void *fn2(int) { ... }
    long fn3(int, void *) { ... }
    
    APIs api_table = { fn1, fn2, fn3 };
    
    
    // client.cc
    #include "libfoo.h"
    ...
      void *foo_handle = dlopen("libfoo.so", RTLD_LAZY);
      if (!foo_handle) {
         return false;            // library not present
      }
      APIs *table = dlsym(foo_handle, "api_table");
      table->api1();              // calls fn1
      void *p = table->api2(42);  // calls fn2
      long x = table->api3(1, p); // calls fn3
    

    P.S. Accessing your API functions individually using dlsym and pointers does not in itself lead to memory corruption and crashes. Most likely you just have bugs.

    EDIT:
    You can use this exact same technique with a 3rd-party library. Create a libdrmaa_wrapper.so and put the api_table into it. Link the wrapper directly against libdrmaa.so.

    In the main executable, dlopen("libdrmaa_wrapper.so", RTLD_NOW). This dlopen will succeed if (and only if) libdrmaa.so is present at runtime and provides all API functions you used in the api_table. If it does succeed, a single dlsym call will give you access to the entire API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java application using threads, which uses several Lock object instances to
I have an application which uses C# for front end and C++ DLL for
I have a web application which uses membership and profiles. I successfully used the
I have a web-application which uses hibernate and for some reason every thread (httprequest
I have a web application which uses URLs that look like this: http://library.example.com/Register.aspx?query=academic&key=586c70bb-5683-419c-aae9-e596af9ab66a (The
I have an application that I have to run as Administrator. One small part
For part of my application I have a need to create an image of
We have a windows application that contains an ActiveX WebBrowser control. As part of
I have a small lightweight application that is used as part of a larger
I have a trivial console application in .NET. It's just a test part of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.