EmbDev.net

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


von Kirkina A. (Company: no) (alya)


Rate this post
useful
not useful
1
if(S_ISDIR(statbuf.st_mode))
2
             printf("d");
3
        else if(S_ISCHR(statbuf.st_mode))
4
            printf("c");
5
        else if(S_ISBLK(statbuf.st_mode))
6
            printf("b");
7
        else if(S_ISREG(statbuf.st_mode))
8
            printf("-");
9
        else if(S_ISFIFO(statbuf.st_mode))
10
            printf("f");
11
        else if(S_ISLNK(statbuf.st_mode))
12
            printf("l");
13
        else if(S_ISSOCK(statbuf.st_mode))
14
            printf("s");
I read the manual here 
https://www.gnu.org/software/libc/manual/html_node/Testing-File-Type.html
This code after compilation produces this error, if I comment on the 
line with this error, then the error disappears

: Edited by User
von Jack (Guest)


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

von Peter II (Guest)


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

on a linker error a include do not help

von Markus F. (mfro)


Rate this post
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
von Kirkina A. (Company: no) (alya)


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

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

von Kirkina A. (Company: no) (alya)


Rate this post
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

von Markus F. (mfro)


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

Ah, yes.

Compile with
1
-D_XOPEN_SOURCE=500

man 2 stat

should have shown you that.

von Kirkina A. (Company: no) (alya)


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

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

von Rolf Magnus (Guest)


Rate this post
useful
not useful
Kirkina A. wrote:
>> Compile with
>>
1
>> -D_XOPEN_SOURCE=500
2
>>
>>
>> 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:
1
st_mode
2
              This field contains the file type and mode.  See inode(7) for
3
              further information.

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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.