10

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?

blow
  • 12,811
  • 24
  • 75
  • 112

2 Answers2

16

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.

Diego Garcia
  • 1,134
  • 1
  • 12
  • 25
  • Hi Diego, where can i find this "add" dialog? I'm using MPLAB X IDE. – blow May 20 '12 at 14:43
  • 1
    Just go to the Project Menu -> Add Files To Project – Diego Garcia May 20 '12 at 15:32
  • This is MPLAB X not old MPLAB IDE, so it is different! – blow May 20 '12 at 15:39
  • 1
    Sorry about that, let me download and I answear you in a few minutes. – Diego Garcia May 20 '12 at 15:50
  • It is not necessary :) i found a solution, in project c18 properties there is an option where "include directories". Including libr directory works. – blow May 20 '12 at 16:26
  • 1
    The key here is to realize that #include only looks in the compiler's "include directories", not the project's "source folders". – Jeanne Pindar Aug 22 '13 at 14:18
  • 1
    To generalize this a little, I'd add to Diego's answer, if you are using XC32 rather than C18, you can look in "Project Properties" -> "XC32 (Global Options)" -> "xc32-gcc" There, you will find a drop down select box "Option Categories:", including "Preprocessing and messages". Select the "Include Directories" item from the table and browse to indicate the directory you'd like to add – OYRM Aug 25 '14 at 16:53
1

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.

Rick G
  • 11
  • 1