Page 1 of 1

How to add header and source files to project

Posted: Fri Feb 21, 2020 2:51 pm
by christian28
Hi all
I'm using eclipse and an esp32 wroom module.

I already setup the environment.
For simple projects like blink example and hello world example it's no problem to build, flash and debug. This works very fine.

Only problem is how to add header and sourcefiles?
As example: I want to write a mathfunction in another file and call the function from main. Eclipse always says that theres no reference. Please see attached files.

Best regards
Christian

Re: How to add header and source files to project

Posted: Fri Feb 21, 2020 9:46 pm
by ESP_krzychb
Hi christian28,

Do you have "CMakeLists.txt" files in your project?
Is "test_header.c" included in "CMakeLists.txt" in your "main" folder?

I think the safest way to start a new project is by going to File > New > Espressif IDF Project. This will set the key files for you. Then add your extra files and update CMakeLists.txt.

Please check https://github.com/espressif/esp-idf/tr ... r/examples how this is done for small typical projects or see formal description in https://docs.espressif.com/projects/esp ... le-project.

Re: How to add header and source files to project

Posted: Sat Mar 06, 2021 1:31 am
by coldsquall
I just experienced a similar issue

Here's what to do to get past it:

Open your CmakeLists.txt file and include this line to the bottom if it is not already there:

Code: Select all

idf_component_register(SRCS "main.c" "cam.c" "sdcard.c"
                    INCLUDE_DIRS  ".")                    
Your CMakeLists.txt should look like this now:

Code: Select all

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

set(COMPONENT_SRCS "main.c" "cam.c" "sdcard.c")
set(COMPONENT_ADD_INCLUDEDIRS "")

register_component()

idf_component_register(SRCS "main.c" "cam.c" "sdcard.c"
                    INCLUDE_DIRS  ".")
NB: Replace main.c, cam.c and sdcard.c in the code above with the names of your source files

Re: How to add header and source files to project

Posted: Thu Jul 01, 2021 2:55 pm
by yakdag
just got same problem but couldn't fix.
after update like advised i got another error ?