EmbDev.net

Forum: ARM programming with GCC/GNU tools ls.c:(.text+0x2dc): undefined reference to `S_ISSOCK'


Author: Kirkina Alya (Company: no) (alya)
Posted on:

Rate this post
0 useful
not useful
if(S_ISDIR(statbuf.st_mode))
             printf("d");
        else if(S_ISCHR(statbuf.st_mode))
            printf("c");
        else if(S_ISBLK(statbuf.st_mode))
            printf("b");
        else if(S_ISREG(statbuf.st_mode))
            printf("-");
        else if(S_ISFIFO(statbuf.st_mode))
            printf("f");
        else if(S_ISLNK(statbuf.st_mode))
            printf("l");
        else if(S_ISSOCK(statbuf.st_mode))
            printf("s");
I read the manual here 
https://www.gnu.org/software/libc/manual/html_node...
This code after compilation produces this error, if I comment on the 
line with this error, then the error disappears

: Edited by User
Author: Jack (Guest)
Posted on:

Rate this post
0 useful
not useful
#include <sys/stat.h>

Author: Peter II (Guest)
Posted on:

Rate this post
0 useful
not useful
Jack wrote:
> #include <sys/stat.h>

on a linker error a include do not help

Author: Markus F. (mfro)
Posted on:

Rate this post
0 useful
not useful
Peter II wrote:
> on a linker error a include do not help

sure it does.

An undefined preprocessor symbol ends up in linker errors.

The OP should have received meaningful compiler warnings much earlier 
already, however (which he appears to ignore but shouldn't).

: Edited by User
Author: Kirkina Alya (Company: no) (alya)
Posted on:

Rate this post
0 useful
not useful
Jack wrote:
>
> #include <sys/stat.h>
> 

In my code this inclusion is connected, see past posts.

Author: Kirkina Alya (Company: no) (alya)
Posted on:

Rate this post
0 useful
not useful
Markus F. wrote:
> Peter II wrote:
>> on a linker error a include do not help
>
> sure it does.
>
> An undefined preprocessor symbol ends up in linker errors.
>
> The OP should have received meaningful compiler warnings much earlier
> already, however (which he appears to ignore but shouldn't).

What then do

Author: Markus F. (mfro)
Posted on:

Rate this post
0 useful
not useful
Kirkina A. wrote:
> What then do

Ah, yes.

Compile with
-D_XOPEN_SOURCE=500

man 2 stat

should have shown you that.

Author: Kirkina Alya (Company: no) (alya)
Posted on:

Rate this post
0 useful
not useful
Markus F. wrote:
> Kirkina A. wrote:
>> What then do
>
> Ah, yes.
>
> Compile with
>
> -D_XOPEN_SOURCE=500
> 
>
> man 2 stat
>
> should have shown you that.

man 2 stat did not show it.
Now everything works and the problem is solved thanks

Author: Rolf Magnus (Guest)
Posted on:

Rate this post
0 useful
not useful
Kirkina A. wrote:
>> Compile with
>>
>> -D_XOPEN_SOURCE=500
>> 
>>
>> man 2 stat
>>
>> should have shown you that.
>
> man 2 stat did not show it.

Seems this has been moved to a separate man page lately. On my linux 
system, this is mentioned in man 2 stat, but the latest version of the 
linux man page project 
(http://man7.org/linux/man-pages/man2/stat.2.html) just says:
st_mode
              This field contains the file type and mode.  See inode(7) for
              further information.

and the inode man page says:
The definitions of most of the above file type test macros are
provided if any of the following feature test macros is defined:
_BSD_SOURCE (in glibc 2.19 and earlier), _SVID_SOURCE (in glibc 2.19
and earlier), or _DEFAULT_SOURCE (in glibc 2.20 and later).  In
addition, definitions of all of the above macros except S_IFSOCK and
S_ISSOCK() are provided if _XOPEN_SOURCE is defined.  The definition
of S_IFSOCK can also be exposed by defining _XOPEN_SOURCE with a
value of 500 or greater.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig