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 7171747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:28:31+00:00 2026-05-28T15:28:31+00:00

Is it possible to (and, if so, how does one) determine the shared libraries

  • 0

Is it possible to (and, if so, how does one) determine the shared libraries of an application that are used by an application at runtime? Basically, can I programmatically obtain the the output of ldd? Preferred C/C++ solution does not just jump to execute ldd on the command-line.

Consider the following:
I have a driver application that calls doAction() from a shared library libfoo. I compile the application once and then set LD_LIBRARY_PATH to an appropriate directory containing a libfoo with the doAction() symbol defined. This way, I can have multiple implementations of doAction() in different libfoos but only ever compile an application once.

A real world example would be a professor having a class of students implement doAction(). Instead of compiling a test harness against each student’s implementation of doAction(), the students submit a shared library and the professor can simply change LD_LIBRARY_PATH to evaluate each student.

My goal in obtaining the library currently being used is to perform an md5sum on the library at runtime to ensure I’m calling the correct library. In the contrived example, all students would submit the md5sum of their library and the professor could match the running executable + shared library (database lookup, log to file, …) to the student, to prevent an accident in setting LD_LIBRARY_PATH effecting another student’s grade (forgot to change LD_LIBRARY_PATH to David’s directory and ran again with Bill’s libfoo).

  • 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-28T15:28:33+00:00Added an answer on May 28, 2026 at 3:28 pm

    Since it looks like you’re using something UNIX-y, just use dlopen instead of dynamically linking your driver app against the missing symbol.

    Full sequence is:

    1. iterate over all submitted .so library filenames somehow (maybe you have one directory with studentname.so or something)
    2. load each library
    3. get the entry point function
    4. call it
    5. unload library (optional, I guess)

    like so:

    void *lib = dlopen(filename, RTLD_LOCAL);
    void *libfun = dlsym(lib, "doAction");
    if (libfun == NULL)
        cout << "student failed by not providing doAction() in " << filename << endl;
    else {
        void (*doAction)(void) = (void (*)(void)) libfun;
        // no, I can't remember the correct syntax for casting to function pointer
        cout << "calling " << filename << ":doAction()" << endl;
        doAction();
        // is there some way to tell if it succeeded?
        cout << "unloading " << filename << endl;
        dlclose(lib);
    }
    

    Notes:

    • if the interface is the same in each case (ie, void (*)()), you could make this configurable by directory name and symbol name, and it’d work for more than one test
    • in fact, if the interface is NOT what you expect, the function pointer cast will do horrible things, so careful with this
    • finally, if the student used C++, their function name symbol will be mangled. Tell them to declare the entry-point as extern "C" void doAction() to avoid that.
    • the RTLD_LOCAL flag should stop anything in one student’s library interfering with another (if you don’t unload), but there are other flags it may be sensible to add
      • specifically, RTLD_NOW will cause dlopen to fail if the student lib has an unresolved external reference it can’t figure out (so you can handle it gracefully, by failing them): otherwise your program may just crash when you call doAction.

    Although I think the above is better than the solution you’re directly asking for help with, I did also find a reference to dl_iterate_phdr while double-checking the docs. If you’re on Linux specifically, and if the dl_phdr_info.dlpi_name is actually the filename … you might be able to get it that way.

    I still think it’s much uglier, though.

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

Sidebar

Related Questions

Does any one know if its possible to animate app.current.mainwindow.width so that you get
cgi.escape seems like one possible choice. Does it work well? Is there something that
Is it possible to use javascript to determine what color is one shade darker
One of the frustrations with the standard TreeView is that you can't show a
I want to build an application that can set up a set amount of
I have an application that receives information from a database, and is used to
Possible Duplicate: Does anyone know of a good C# API for Subversion? I'm designing
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: What does map(&:name) mean in Ruby? I was watching a railscast and
Possible Duplicate: Why does C# not provide the C++ style ‘friend’ keyword? I'd like

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.