stat method not found in libc.so.6

Viewed 276

Using Dart FFI I'm trying to dynamically load the linux/posix 'stat' function.

I've assumed that the function is in the libc.so.6 library but when I attempt to load it I get the error:

Invalid argument(s): Failed to lookup symbol (/lib/x86_64-linux-gnu/libc.so.6: undefined symbol: stat)

I'm successfully loading other functions from the libc.so.6 library so my dynamic loading technique is working correctly.

I have two theories:

  1. stat is a macro for xstat and as such stat no longer exists.
  2. stat is in another library that I've not been able to groc.

Ideally I want to use stat rather than xstat as I need this code to also work on osx which as far as I can tell doesn't support xstat. Help?

1 Answers

I have two theories:

There is no need to theorize: you can just look:

echo "#include <sys/stat.h>" | gcc -xc - -E -dD | less
nm -AD /lib/x86_64-linux/gnu/*.so* | grep ' stat$'

will tell you everything you need to know (your first theory is correct).

I want to use stat rather than xstat

You can't: it doesn't exist (when using GLIBC).

I need this code to also work on osx which as far as I can tell doesn't support xstat.

Your code can detect the platform it's running on and adjust. This is the price of using non-portable mechanisms, such as FFI.

Related