I'm using the MPLAB IDE and the XC8 compiler for a C project for PIC18 devices. I'm building a project with multiple source files and don't know how to make the structure.
In the project, I have the following things:
- A file main.c where the main code is located. From here, several files are included:
- xc.h: to define chip-specific variables and so
- stdlib.h, stdio.h, plib.h, delays.h: for the compiler's functions
- enc28j60.h: a homebrew file with definitions and prototypes
- A file enc28j60.c, where the functions of the prototypes in enc28j60.h go
I cannot compile enc28j60.c as standalone file because it depends on definitions in main.c.
I have a few questions on how to set this project up:
- Should I add enc28j60.c to the source files of my MPLAB project? If I do this, MPLAB tries to compile the file, which fails. If I don't do this, the linker cannot find the symbols that are defined in enc28j60.c and prototyped in enc28j60.h.
- Should I
#include
enc28j60.c from somewhere? If not, how does MPLAB know where to get the file? - Should I add enc28j60.h to the header files of my MPLAB project?
- Should I
#include
enc28j60.h from somewhere? Right now, I do this in main.c, after the definitions enc28j60.h needs in order to run (and not throw#error
s).