functions from other files are undefined to main.c

Ali_Makhlouf
Posts: 8
Joined: Mon Dec 13, 2021 3:49 pm

functions from other files are undefined to main.c

Postby Ali_Makhlouf » Wed Mar 30, 2022 12:14 pm

I am trying to make LCD project based on i2s driver then I faced a problem that the functions are undefined. Then I made a simple main.c file and a another .h/.c files that contain a sum functions and still tells me the function is undefined.

main.c code:

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "sdkconfig.h"
#include "esp_heap_caps.h"
#include "esp_log.h"

#include "../components/components.h"

void app_main(void)
{

	uint8_t x = 3, y = 4, z = 0;

	z = sumq(x, y);

	while(1);

}
===========================================
components.h code:

Code: Select all

#ifndef   __temp_H__
#define   __temp_H__

#include <stdio.h>

uint8_t sumq(uint8_t s1, uint8_t s2);

#endif
===========================================
components.c code:

Code: Select all

#include "sdkconfig.h"
#include "components.h"

uint8_t sumq(uint8_t s1, uint8_t s2)
{
	return s1 + s2;
}	
===========================================
the project structure below (img1)
Image

and the error is as below (img2)
Image


then I moved the function(sumq) definition and prototype to main.c file and it compiled, but they didn't compile in the components.h/.c files. Looks like it's a linker problem

can you help me solve this problem?

Thanks.
Attachments
img2.png
img2.png (43.6 KiB) Viewed 1721 times
img1.png
img1.png (12.35 KiB) Viewed 1721 times

Ali_Makhlouf
Posts: 8
Joined: Mon Dec 13, 2021 3:49 pm

Re: functions from other files are undefined to main.c

Postby Ali_Makhlouf » Wed Mar 30, 2022 1:02 pm

I found the problem.
it was the CMakeList.txt

It should contain all the .h/.c files that should be built within the main.c

the Cmakelists.txt was modified to the following:

Code: Select all

# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES )
set(COMPONENT_PRIV_REQUIRES )



set(COMPONENT_ADD_INCLUDEDIRS "")

idf_component_register(
    SRC_DIRS
        "."
        "../components"
    INCLUDE_DIRS
        "../components"
        )

But Why should do this every time a file is added. Shouldn't this be automatically implemented?

Who is online

Users browsing this forum: No registered users and 97 guests