Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "Undefined reference to function" in Eclipse CDT?

I did setup a C project with Eclipse Photon (4.8.0) for developing a program for the ESP-32. I did configure the IDE according to this official setup instructions.

Flashing the ESP-32 works fine. But as soon as I try to include header files from a sub folder, I run into troubles. I have set up a very simple project to illustrate the issue. The project consists of main.c, base/test.h and base/test.c, whereas the test.h and test.c files only contain one function with the signature void function1(void);.

When I try to call function1() in main.c, I get this error in main.c:

Undefined reference to function1()

Please compare to the attached screenshot, where everything is depicted.

How to solve this issue?

enter image description here

like image 383
salocinx Avatar asked Sep 26 '26 15:09

salocinx


1 Answers

This is not a compiler, but rather a linker error.

Note, with #includeing a header file, you only make the external function known to the compiler. You also need to link to the external function during the linking stage. Make sure you include the compiled object file that contains function1 into the link.

like image 198
tofro Avatar answered Sep 28 '26 06:09

tofro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!