LPCXpresso: Unable to add a header file (undefined reference error)

cancel
Showing results for 
Search instead for 
Did you mean: 

LPCXpresso: Unable to add a header file (undefined reference error)

1,727 Views
kembed
Contributor II

Hi!

I am trying to separate led code in a different file and I am facing following issues:

Issue #1

   I Created a new folder by

   Right clicking project -> New -> Folder -> Folder name = led.

   Now when I try to  create a header file and source file by 

   Right clicking project -> New -> Header File/Source File, I could  not find "led" folder which I just created. Why is led    folder not there?

Issue #2 

   If I create a header file and source file by 

   Right clicking project -> New -> File -> File name = led.h and File name = led.c, and #include "led.h" in my    hello_world_core1.c file, the program is not compiling and gives me the following error:

   

fatal error: led.h: No such file or directory hello_world_core1.c /hello_world_cm0plus/source line 44 C/C++ Problem   

   If I manually include led.h header file in the Include files (-include) by

   Right clicking project -> Properties -> C/C++ Build -> Setting -> MCU C Compiler -> Include files (-include)

   -> ${workspace_loc:/${ProjName}/led/led.h}

   I get the same error

fatal error: led.h: No such file or directory hello_world_core1.c /hello_world_cm0plus/source line 44 C/C++ Problem

   Now if I manually include led.h header file in the Include Paths (-l) by

   Right clicking project -> Properties -> C/C++ Build -> Setting -> MCU C Compiler -> Include paths (-l)

   -> ${workspace_loc:/${ProjName}/led}

   the previous fatal error disappears and but it gives me a new error about a function UpdateLED() which I am calling from    led.c.

   

undefined reference to `UpdateLED' hello_world_core1.c /hello_world_cm0plus/source line 119 C/C++ Problem

Any help would be highly appreciated!

Thanks

0 Kudos
2 Replies

434 Views
converse
Senior Contributor IV

1. If you want to put source into the folder, then you need to create a Source Folder. Its on the same menu.

2. When you create a header file, if it is not in the same folder as the file being compiled, you need to add the folder to the include path

 Right click project -> Properties -> C/C++ Build -> Setting -> MCU C Compiler -> Include paths (-l)

The "Undefined reference" error is a Linker problem, not a compile problem. I guess this is because you have not put led.c into a Source Folder and so it is not being compiled and linked into your application.

0 Kudos

434 Views
somduttacharya
Contributor I

Hello Con,

I am trying a program to get LCD output. My whole program compiles and gives an error lpc_types.h : No such file or directory. I have lpc_types.h header in one of my created lcd.h header file. How to add that header file through the steps you have mentioned above. Please Help!!

0 Kudos