Ana Matijanovic
Ana Matijanovic

Reputation: 277

How do I add my own header in Keil?

I have main.c and I want to include my header. I made header led.h (right click on user -> Add new item to Group User). But like on picture, it didnt appear. I only got new window where I can write my code for header, but I still cant include it in main (getting error led.h file not found). What I need to do, to get my header be visible in main.c?

enter image description here

Upvotes: 0

Views: 1309

Answers (1)

Guillaume Michel
Guillaume Michel

Reputation: 1214

By default, Keil does not show the header files in the project tree. You can show them by right clicking on the group and Add existing files to Group. This is only to display nicely your files, but this will not help you when you want to include the header in your c file.

To include led.h in your main.c file, you can try the following options:

  • add the full path in your include for example #include "..\led.h"

  • copy the led.h file in the same folder as the main.c file and include it #include "led.h"

  • update your projects settings (Options for target -> C/C++ -> Include path) to add all your paths and include led.h #include "led.h"

Upvotes: 1

Related Questions