pipe2 implicit declaration despite include unistd.h

Asked by Jackson Smith on 2019-02-06

Dear Ubuntu Community,

We have a fairly fresh install of Ubuntu 18.04 Desktop. On this system, I'm trying to compile a C language program which makes a call to the Linux-specific pipe2( ) system call.

Critically, the top of the source file says:

#include <fcntl.h>
#include <unistd.h>

But gcc gives me the following warning:

$ gcc *.c -o metserver -lrt
    metpipe.c: In function ‘metpipe’:
    metpipe.c:102:11: warning: implicit declaration of
    function ‘pipe2’; did you mean ‘pipe’?
    [-Wimplicit-function-declaration]
    if ( pipe2 ( fd , flags ) == -1 )
          ^~~~~
          pipe

Specifically, metserver makes a call to metpipe which then calls pipe2( ). But both source files include my met.h header file at the top. met.h includes the unistd.h and fcntl.h headers. This all compiled and ran smoothly on a previous installation of Ubuntu 14.04 on the same system.

The only thing similar to this that Google could find was here: https://forums.freebsd.org/threads/gmake-fails-compilation-with-pipe2-even-if-unistd-h-is-included.66873/

I look forward to any suggestions that might resolve this issue.

Cheers,
js

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu glibc Edit question
Assignee:
No assignee Edit question
Solved by:
Jackson Smith
Solved:
2019-02-06
Last query:
2019-02-06
Last reply:
Jackson Smith (jsdpag) said : #1

Okay, prior to this I hadn't heard of Feature Test Macros: https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html

Adding

#define _GNU_SOURCE

to the top of the source file was required for the non-POSIX pipe2( ) system call to be recognised. I guess that this was somehow implicit in my previous setup with Ubuntu 14.04.