How to add header and source files to project

christian28
Posts: 2
Joined: Wed Feb 19, 2020 2:41 pm

How to add header and source files to project

Postby christian28 » Fri Feb 21, 2020 2:51 pm

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
Attachments
test_header.h
(190 Bytes) Downloaded 815 times
test_header.c
(157 Bytes) Downloaded 677 times
main.c
(98 Bytes) Downloaded 713 times

User avatar
ESP_krzychb
Posts: 400
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: How to add header and source files to project

Postby ESP_krzychb » Fri Feb 21, 2020 9:46 pm

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.

coldsquall
Posts: 1
Joined: Sat Mar 06, 2021 1:21 am

Re: How to add header and source files to project

Postby coldsquall » Sat Mar 06, 2021 1:31 am

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

yakdag
Posts: 1
Joined: Thu Jul 01, 2021 2:44 pm

Re: How to add header and source files to project

Postby yakdag » Thu Jul 01, 2021 2:55 pm

just got same problem but couldn't fix.
after update like advised i got another error ?
Attachments
error.png
error.png (16.24 KiB) Viewed 12883 times

Who is online

Users browsing this forum: Teh2024 and 33 guests