F_SETPIPE_SZ undeclared
Asked Answered
M

2

6

I have included following headers:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

I have also tried to use

#define _GNU_SOURCE

before #include <unistd.h>, but it also does not help.

I try to use fcntl and pass it F_SETPIPE_SZ as second argument, but I keep getting this error message:

error: ‘F_SETPIPE_SZ’ undeclared (first use in this function)

I actually found out that I don't need this, but I'm just curious why I can't use it.

Thank you.

So here's solution, thanks to Chrono Kitsune: Put

 #define _GNU_SOURCE

before any includes.

Mohl answered 20/8, 2014 at 18:25 Comment(6)
How are you calling fcntl. Can you post that in your question?Occidentalize
You should #define _GNU_SOURCE before including any headers. I doubt that will help, but it is worth saying. What does uname -r show? If it is less than 2.6.35, you shouldn't have F_SETPIPE_SZ. The man page I have documents it as being available since Linux 2.6.35.Romany
Thanks, it actually did solve problem, I don't know how but it did. And one more problem to. Awesome! Thank you. (And no, my kernel is not that old :) )Mohl
@ChronoKitsune don't define like this. the formal way to enable it is by cli: gcc --std=gnu blabla.Intuitivism
You shouldn't add the answer to question. Instead post it as an answer. You're allowed to answer your own questions, and you'll be to accept in a day or two.Mention
@HuStmpHrrr You're correct, but since _GNU_SOURCE is a Linux glibc feature test macro (man feature_test_macros), just like _POSIX_C_SOURCE and _XOPEN_SOURCE, it is perfectly reasonable to simply define the macro on a per-file basis before including any headers. The man page specifically states that it is allowed. The important point is to define it before any headers are included, meaning either on the command line or in a file.Romany
M
14

So here's the solution, thanks to Chrono Kitsune:

Put

#define _GNU_SOURCE

before any includes.

You should also pay attention to Chrono Kitsune's other comment.

Mohl answered 23/8, 2014 at 15:1 Comment(0)
B
2

F_SETPIPE_SZ/F_GETPIPE_SZ are relatively recent. Older kernels (e.g. 2.6.32 as used in RHEL6) don't have them. If you look in /usr/include/linux/fcntl.h and these constants aren't defined, then this API isn't going to work and you'll have to find some way to bypass it in whatever you're building.

Bootle answered 4/3, 2016 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.