Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "error: implicit declaration of function ‘fileno’" when I try to compile on Linux but not on a Mac

Tags:

c

linux

macos

As the title states, I am getting the following error: "implicit declaration of function ‘fileno’" when I try to compile on Linux but not on a Mac. I know I can fix it with the simple line int fileno(FILE *stream);, but I want to know why this happening.

like image 810
helppls Avatar asked Nov 08 '25 09:11

helppls


1 Answers

You should not declare functions provided by a system library. You should properly include an appropriate header.

Since fileno is not a standard C function, it is not normally declared by in <stdio.h> . You have to define a suitable macro in order to enable the declaration.

man fileno

Requirements for glibc (see feature_test_macros(7)):

fileno(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE

Defining any of the the three macros before inclusion of should do the trick.

like image 200
n. 1.8e9-where's-my-share m. Avatar answered Nov 10 '25 03:11

n. 1.8e9-where's-my-share m.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!