1

I'm able to compile the following with no warnings using gcc -c program.c -o program.o

In program.h

#include<math.h>

In program.c

#include<sys/types.h>
#include"program.h"

But not this:

In program.h

#include<sys/types.h>
#include<math.h>

In program.c

#include"program.h"

If done the latter way, I get implicit declarations of all functions called from any libraries included after sys/types.h. For example:

program.c:352:55: warning: incompatible implicit declaration of built-in function ‘pow’
program.c:352:55: note: include ‘<math.h>’ or provide a declaration of ‘pow’

Why is this?

Evan Hendler
  • 342
  • 1
  • 12

1 Answers1

1

So, the error was caused by a file program.h.gch within the compilation directory. These are precompiled headers. gcc looks for these prior to actually compiling. The compiler was using a precompiled header without #include sys/types.h, vice program.h which had the correct includes.

See What is a .h.gch file? for more information.

Evan Hendler
  • 342
  • 1
  • 12