2

I have a program that went like this:

//this is main.c
#include <stdio.h>
#include <stdlib.h>
...
#include "fileA.c"
#include "fileB.c"
...

//rest of main file

which worked fine but now when I replicated the exact same project (in VS) all the other files in the project don't seem to recognize the standard library #includes from some reason.

any help please?

Tom
  • 69
  • 7
  • 3
    C programs are compiled file by file, so in order for `#include`s to be recognized they need to be included in every file. Also, you should only include [header files](https://stackoverflow.com/questions/333889/why-have-header-files-and-cpp-files), not source files. – apilat May 12 '19 at 20:34
  • 1
    You should not normally `#include` C source files — you `#include` headers, but not (normally) source code. There are exceptions — but they're rare and should remain exceptional. – Jonathan Leffler May 12 '19 at 20:58

1 Answers1

4

Other files are independent files. As such, you must include the relevant header files in those files as well. Also, it is not considered a good practice to include .c files as it can easily result in linking errors due to multiple definitions.

machine_1
  • 4,266
  • 2
  • 21
  • 42