Search code examples
clinuxstat

stat() does not work for .so files


I am facing an issue with stat() . stat() does not seem to be working with .so files. It gives the error

No such file or directory .

Why is this happening?

As requested I paste a portion of the code:

int main()
 {
    char str[300];
    struct stat str_buf;
    strcpy(str,"path/to/my/library/libfuncs.so");

    if(stat(str,$str_buf)==-1)
       perror("stat");
     ....
  }

Thus the error comes as stat No such file or directory

But the same code works fine for other files and directories. libfuncs.so is my generated shared library.


Solution

  • Many ".so" files are in fact symbolic links due to versioning issues. You might want to use lstat() in those cases, to stat the actual link.

    The error you're getting ("No such file or directory") seems to imply that the symbolic link is pointing at something that doesn't exist. In these cases stat:ing the link itself helps, but of course that might not be what you want to do. Check the link's target. If the path in the link is relative, perhaps you're executing the code from a different directory?