Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'implicit declaration of function 'pipe2' is invalid in C99'

Tags:

I'm trying to build my library but a file called evutil.c fom libevent is giving me a hard time.

libevent/evutil.c: error: implicit declaration of function 'pipe2' is invalid in C99

The code involved is:

    if (pipe2(fd, O_NONBLOCK|O_CLOEXEC) == 0)
        return 0;

I can't update my code to c11 right now. How should I change the code to not get this error anymore?

like image 729
Carla Camargo Avatar asked Mar 27 '19 20:03

Carla Camargo


People also ask

What does implicit declaration of function is invalid in c99 mean?

implicit declaration of function means you do not have Prototypes for your functions. You should have a Prototype before the function is used. "call the block" I assume your Blocks are functions. 9/30/2020.

How do you fix an implicit function declaration?

Function name typo: Often the function name of the declaration does not exactly match the function name that is being called. For example, startBenchmark() is declared while StartBenchmark() is being called. I recommend to fix this by copy-&-pasting the function name from the declaration to wherever you call it.

Why is implicit declaration error in C?

Such an 'implicit declaration' is really an oversight or error by the programmer, because the C compiler needs to know about the types of the parameters and return value to correctly allocate them on the stack.

What is implicit declaration of function?

If a name appears in a program and is not explicitly declared, it is implicitly declared. The scope of an implicit declaration is determined as if the name were declared in a DECLARE statement immediately following the PROCEDURE statement of the external procedure in which the name is used.


1 Answers

This isn't a C99 issue. You need to include the header for pipe2. According to the pipe2 manual that is unistd.h.

Why libevent isn't doing this itself is a valid question.

like image 178
Schwern Avatar answered Oct 04 '22 12:10

Schwern