Jump to content

Compiler doesn't recognize lstat()

- - - - -

  • Please log in to reply
3 replies to this topic

#1
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
This is just downright bizarre. I have the following program:


#include <unistd.h>

#include <dirent.h>

#include <sys/stat.h>


...


lstat( fil->d_name, &inode );

...


And I get this error:


Warning: implicit declaration of function 'lstat'


I checked the spelling in the #include multiple times. I looked at /usr/include/sys/stat.h and found the prototype for lstat() there. I even copied and pasted the function name to my program for good measure. It still doesn't recognize it. It works when I use stat() and fstat(), but not lstat(). lstat64() doesn't work either.

I have not modified /usr/include/sys/stat.h in any way. The compiler just doesn't recognize lstat() for some very strange reason.
Programming is a journey, not a destination.

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
What's your version of gcc?

EDIT: Oh, also, any compiler flags?
Wow I changed my sig!

#3
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts

ZekeDragon said:

What's your version of gcc?

EDIT: Oh, also, any compiler flags?

The version is 4.3.2. The compiler flag is std=c99.

It compiles on my Mac but not on my Linux box, so I think it has to do with a glitch in the implementation.

The version on my Mac is 4.0.1, and it's the Apple version, not the GNU version.

Here's what's in the header file on my Linux box:


#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED

#  ifndef __USE_FILE_OFFSET64

extern int lstat (__const char *__restrict __file, struct stat *__restrict __buf) __THROUW __nonull ((1, 2));

#  else

#    ifdef __REDIRECT_NTH 

extern int __REDIRECT_NTH (lstat, (__const char *__restrict __file, struct stat *__restrict __ __buf), lstat64) __nonull ((1, 2));

#    else

#      define lstat lstat64

#    endif

#  endif

#  ifdef __USE_LARGEFILE64

extern int lstat64 (__const char *__restrict __file, struct stat64 *__restrict __buf) __THROW __nonull ((1, 2));

#  endif

#endif


I tested all the macros and __USE_BSD and __REDIRECT_NTH are defined but __USE_FILE_OFFSET64 isn't, which means the first prototype is used. I don't know if that's relevant.
Programming is a journey, not a destination.

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
You must understand what you are setting up your compiler to do or not do.

Invoking `c99` or `gcc --std=c99` will cause the macro definition __STRICT_ANSI__ to help the compiler replicate a C99 standard environment, where lstat and other extensions will not be defined.

You must either define the macro _GNU_SOURCE* before any non-strictly-C99 headers (unistd.h, stat.h, etc.) or define the GNU extensions to C99, i.e.`--std=gnu99`

*

"" said:

— Macro:_GNU_SOURCE
If you define this macro, everything is included: ISO C89, ISO C99, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions. In the cases where POSIX.1 conflicts with BSD, the POSIX definitions take precedence.

Alexander.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users