tags:

views:

120

answers:

4

I am using a dev system where I have to specify the lib name when accessing a function inside it.

I've used functions like open() before, and somehow found out that they're in libc.so.

Now I want to use lstat(), but it appears that this one is not in libc. Sadly, the man pages I looked at do not document the location of the functions.

So, two questions: 1. Can someone tell which lib hosts lstat? 2. How can I generally find this out? Other than using grep "name" on all files in the lib folder, I mean.

A: 

From the manpage (man lstat):

LSTAT(P)

NAME
       lstat - get symbolic link status

SYNOPSIS
       #include <sys/stat.h>

       int lstat(const char *restrict path, struct stat *restrict buf);
ar
OP wants to know what library the functions eventually get stored in, not what header file.
Duck
A: 

This is one way to do it:

tomislav@malik:~$ cd /usr/lib
tomislav@malik:/usr/lib$ grep "lstat()" *
Binary file libperl.so.5.10 matches
Binary file libperl.so.5.10.0 matches
tomislav@malik:/usr/lib$ 
Tomislav Nakic-Alfirevic
libperl? That can't be right. Use the 'nm' command instead. Such as `nm lib*.so* | grep lstat`.
Martin Wickman
Yes, the grep shows also _imports_, I believe, thus the wrong result about libperl.
Thomas Tempelmann
libperl matches because it contains the string `lstat()`, which is a Perl function implemented here. That has little to do with the underlying syscall.
ephemient
A: 

lstat is in libc, and libc is linked in by default. You don't need to do anything to use lstat besides including the header file for it #include <sys/stat.h>

man pages usually state which library they are in.

nos
I think I clearly pointed out that this is not about C but about a dev env where I need to specify the lib explicitly.
Thomas Tempelmann
Nevertheless, it is in libc, so link to libc. If this is is some environment that has little to do with what's normally found on a linux machine you need to tell us what kind of environment this is.There is no stock way to know where functions resides besides its documentation - which sometimes is lacking.
nos
nos -- the only reason why I could not find it in libc was that it wasn't declared there, as you pointed out above. I've solved it now, thanks.
Thomas Tempelmann
if you edit this reply, I can upvote you :)
Thomas Tempelmann
+1  A: 

Build a simple testcase in C, compile it and run 'ldd -r' on it to check what libs are loaded. If you don't get lstat() in C then you have a problem on your dev env. Or this env dates back before the age of symlinks :-)

bernard
Good idea.In this case the problem actually was that there is really no lstat in the lib, but only __lxstat. Which could be seen in the headers, though.
Thomas Tempelmann