I managed to get this working by modifying my library and header files a bit.
At first, I added a file main.h where all the prototypes, #define
s and #include
s would go. Then, in every .h
, file, I added this on top:
#ifndef SOME_LIB_IDENTIFIER // makes sure the lib only gets included once,
#define SOME_LIB_IDENTIFIER // has to be specific for every lib
#include "main.h" // to make sure everything's initialized (this line of course not in main.h)
And the last line of every .h
file would be:
#endif
I added #include "enc28j60.h"
to the top of the enc28j60.c file. This file now can be compiled.
In main.h, I added includes for xc.h, plib.h, stdlib.h, stdio.h and enc28j60.h. I nowhere included .c
files.
I added both the main and enc28j60 header and source files to my MPLAB project. The source files get compiled well, both. The result is linked together.
In short
- Add a main.h where all prototypes,
#define
s and#include
s go - Add a header and footer to all your header file to make sure they're only included once. Also include main.h from these headers, to make sure every file uses the same definitions
- Include a source file's corresponding .h file at the very first line of your source file. Do not include .c files
- Add all header and source files (that are not built into the compiler) to your MPLAB project
- Build (F10) should compile all files and link them together correctly