Use external header files in MPLAB X IDE

blow picture blow · May 20, 2012 · Viewed 33.2k times · Source

I have a folder with some .h and .c files and I want to use header files in my projects.

I have included them in "Header Files" folder of my project using "Add Existing Item" but when i try to "#include" them compiler(mplabc18\v3.41) say "unable to locate file xyz.h"

So, what should i do to use these files without copying them into the project folder?

Answer

Diego Garcia picture Diego Garcia · May 20, 2012

Just add the header to the project using the "add" dialog and select "this file is for this project, use relative path" dont remember if it is exac this text but its something like.

After that just do the normal declaration in your file:

#include "your_header.h"

This should work fine.

--UPDATE

To work with the new MPLAB X

Do the follow:

  1. Click on the File-> Project Properties

  2. Select the Conf -> C18 (Global Options) -> mcc18
    For XC8, this is under Conf > XC8 compiler

  3. Click on the "..." button of the propertie "Include directories"

  4. Click on "Browse Button"

  5. Locate you project directory

  6. Click on Open, then Ok and Apply

  7. Build your app !

Now it should work.