Use external header files in MPLAB X IDE
Asked Answered
V

2

11

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?

Valetudinarian answered 20/5, 2012 at 14:33 Comment(0)
R
17

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.

Romney answered 20/5, 2012 at 14:40 Comment(7)
Hi Diego, where can i find this "add" dialog? I'm using MPLAB X IDE.Valetudinarian
Just go to the Project Menu -> Add Files To ProjectRomney
This is MPLAB X not old MPLAB IDE, so it is different!Valetudinarian
Sorry about that, let me download and I answear you in a few minutes.Romney
It is not necessary :) i found a solution, in project c18 properties there is an option where "include directories". Including libr directory works.Valetudinarian
The key here is to realize that #include only looks in the compiler's "include directories", not the project's "source folders".Malkamalkah
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 addMarla
T
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.

Trott answered 5/9, 2014 at 1:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.