"undefined reference to" error

moriteru
Posts: 3
Joined: Fri Feb 01, 2019 4:49 am

"undefined reference to" error

Postby moriteru » Fri Feb 01, 2019 5:04 am

Hi guys.

When I tried to compile my source, it failed saying
undefined reference to `test_func'
.

Here is my directory structure.
- esp-idf
- my_lib
---- test_func.h
---- test_func.c
- my_project
---- main
-------- main.c
Here is main.c source code.

Code: Select all

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_log.h"
#include "sdkconfig.h"
#include "../../my_lib/test_func.h"

void app_main()
{
	test_func();
}
Here is test_func.h source code.

Code: Select all

void test_func(void);
Here is test_func.c source code.

Code: Select all

#include "esp_log.h"
#include "test_func.h"

void test_func() {
	ESP_LOGI("TEST", "TEST");
}
What is wrong?
Sorry for such a beginner question, but I'm not used to c programming.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: "undefined reference to" error

Postby ESP_Sprite » Fri Feb 01, 2019 7:07 am

my_lib is not 'seen' by the make system. Either put test_func.* in the main/ folder, or make my_lib into a proper component that's either placed under your my_project/components/ folder, or use EXTRA_COMPONENT_DIRS to refer to it. In general, I'd suggest you give https://docs.espressif.com/projects/esp ... ystem.html a good read-through, as it tells you exactly what the build system expects.

moriteru
Posts: 3
Joined: Fri Feb 01, 2019 4:49 am

Re: "undefined reference to" error

Postby moriteru » Fri Feb 08, 2019 7:18 am

Dear ESP Sprite, Thank you for your reply.

I learnt the build system and I put files in my project folder.

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 171 guests