Thread: dlopen claiming that a linked library does not exist

  1. #1
    Registered User
    Join Date
    Feb 2023
    Posts
    4

    Exclamation dlopen claiming that a linked library does not exist

    For the following C program I get the output: "Error: /usr/local/bundle/ruby/3.0.0/gems/mitie-0.2.1/vendor/libmitie.so: cannot open shared object file: No such file or directory", but the file does exist, and seems to be a valid ELF binary (I did my best to verify with realelf).

    Code:
    #include <stdio.h> 
    #include <dlfcn.h> 
     
    int main(void) { 
        void *handle = dlopen("/usr/local/bundle/ruby/3.0.0/gems/mitie-0.2.1/vendor/libmitie.so", RTLD_NOW); 
        const char *err = dlerror(); 
     
        if (handle && !err) { 
           printf("Handle: %ld\n", (long int)handle); 
        } 
        else { 
           printf("Error: %s", err); 
        } 
     
        return 0; 
    }


    Any thoughts? Thank you so much!

    I should also note that this is running in a Docker container in a Debian based image.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Is the file in your docker container?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2023
    Posts
    4
    Quote Originally Posted by Salem View Post
    Is the file in your docker container?
    Yes, it is

  4. #4
    Registered User
    Join Date
    Feb 2023
    Posts
    4
    Within the docker container I got this output from the "file" command:

    Code:
    /usr/local/bundle/ruby/3.0.0/gems/mitie-0.2.1/vendor/libmitie.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=92cea087cb683f406382dc15e7cb5e6ddd466f5a, not stripped
    So I was thinking it could be an issue with architecture mismatch since I'm building the image on a M1 Mac. So I tried building a multi-architecture image, but I still get the same results.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Can you do 'file' on other .so files ?
    Can you dlopen any of those files?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Feb 2023
    Posts
    4
    Quote Originally Posted by Salem View Post
    Can you do 'file' on other .so files ?
    Can you dlopen any of those files?

    Thank you. I tried that, it turned out to be an architecture mismatch after all. I was confused because building a multi-architecture image didn't resolve the matter, but it turns out the Ruby library currently only supports x86 for Linux. I was able to resolve the matter by forcing the image to only support x86. Thank you again!

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Quote Originally Posted by manpage
    RETURN VALUE
    On success, dlopen() and dlmopen() return a non-NULL handle for the loaded object. On error (file could not be found, was not readable, had the wrong format, or caused errors during
    loading), these functions return NULL.

    On success, dlclose() returns 0; on error, it returns a nonzero value.

    Errors from these functions can be diagnosed using dlerror(3).
    Would dlerror() have told you that?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dlopen not working as expected, help needed
    By josymadamana in forum C Programming
    Replies: 10
    Last Post: 12-06-2012, 04:24 AM
  2. Is dlopen leaking memory?
    By raczzoli in forum C Programming
    Replies: 1
    Last Post: 09-26-2012, 03:03 PM
  3. using shared libraries and dlopen + dlsym
    By eva69 in forum Linux Programming
    Replies: 13
    Last Post: 02-11-2009, 11:50 AM
  4. dlopen, dlsym does not work in Linux as expected
    By balakv in forum C Programming
    Replies: 2
    Last Post: 04-03-2007, 12:44 AM
  5. linked list library
    By sahil_m in forum C Programming
    Replies: 12
    Last Post: 10-30-2005, 08:16 AM

Tags for this Thread