Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

I know this is an old question, but wanted to add another tip since I just stumbled across it myself. If you go back and forth between Windows and Linux systems, be sure to pay attention to the capitalization in the filename. On Windows, it doesn't matter. However, on Linux, you need to be sure your #include reference has the same capitalization as the actual file.

If the file is saved on disk as 'UARTIO.INC', your include needs to be:

#INCLUDE "UARTIO.INC"  **EXACTLY**

If you put it as:

#INCLUDE "UARTIO.inc", or #INCLUDE "uartio.inc"

It will work fine on Windows, but will fail with "Could Not Find Include File" errors on Linux.

Note that setting MPLAB to ignore case sensitivity doesn't matter for this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top