Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting "implicit declaration of function 'fcloseall' is invalid in C99" when compiling to gnu99

Tags:

c

clang

c99

Consider the following C code:

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

void fatal(const char* message){
 /*
  Prints a message and terminates the program.
  Closes all open i/o streams before exiting.
 */
 printf("%s\n", message);
 fcloseall();
 exit(EXIT_FAILURE);
}

I'm using clang 2.8 to compile: clang -Wall -std=gnu99 -o <executable> <source.c>

And get: implicit declaration of function 'fcloseall' is invalid in C99

Which is true, but i'm explicitly compiling to gnu99 [which should support fcloseall()], and not to c99. Although the code runs, I don't like to have unresolved warnings when compiling. How can i solve this?

Edit: corrected tipo.

like image 609
Emanuel Ey Avatar asked Jan 13 '11 12:01

Emanuel Ey


People also ask

How do you correct an implicit declaration of a function?

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.


1 Answers

To include non-standard extensions when you include standard headers you need to define the appropriate feature test macro. In this case _GNU_SOURCE should work.

#define _GNU_SOURCE
#include <stdio.h>

This is independent of -std=gnu99 which enables language extensions, not library extensions.

like image 128
CB Bailey Avatar answered Oct 31 '22 22:10

CB Bailey