Page 1 of 1

Multiple source codes cannot be built

Posted: Fri Feb 14, 2025 1:38 am
by Hiroki
The development environment is ESP-IDF v5.4.0 and VSCode.
Source files are divided by function.
However, an error occurs in the build.
I'm wondering if something is missing, since the sample on Github confirms that multiple source files also build successfully.
Please advise what is missing.
The file structure is
main.c
test.c
test.h
The three files are in the same path.
The addition to main.c is
#include “test.h”
The addition to CMakeLists.txt is “test.c” after SRCS.
If you write code to use a function in test.c in main.c, a build error will occur.
Of course, the build will succeed if the functions of test.c are not written in main.c.
The only information I could find was to append the name of the source file I added to CMakeLists.txt.
What else is needed?

Re: Multiple source codes cannot be built

Posted: Fri Feb 14, 2025 7:32 pm
by nopnop2002
esp-idf contains many samples consisting of multiple sources.

This is one example.

https://github.com/espressif/esp-idf/tr ... le_serving

Re: Multiple source codes cannot be built

Posted: Wed Feb 19, 2025 3:14 am
by Hiroki
Thanks for answering.
But the information I want is not the URL of the sample source, but what exactly it does.
The only information I can find in various languages is to write the source file name in “CMakeLists.txt”, which gives me a build error when I try to put it into practice.
What else do I need to do to get a successful build?
I could not find a solution just by looking at the sample source.

Re: Multiple source codes cannot be built

Posted: Wed Feb 19, 2025 9:13 am
by ESP_Sprite
Can you post the actual text of your main.c, test.c and CMakeLists.txt here? Also the error you get when trying to compile it would be helpful.

Re: Multiple source codes cannot be built

Posted: Wed Feb 19, 2025 12:19 pm
by ok-home
Hiroki wrote:
Wed Feb 19, 2025 3:14 am
Thanks for answering.
But the information I want is not the URL of the sample source, but what exactly it does.
The only information I can find in various languages is to write the source file name in “CMakeLists.txt”, which gives me a build error when I try to put it into practice.
What else do I need to do to get a successful build?
I could not find a solution just by looking at the sample source.
https://docs.espressif.com/projects/esp ... ystem.html

Re: Multiple source codes cannot be built

Posted: Wed Feb 19, 2025 12:31 pm
by nopnop2002
>The only information I can find in various languages is to write the source file name in “CMakeLists.txt”

That's really all.

Code: Select all

set(srcs "main.c" "test.c")

idf_component_register(SRCS "${srcs}" INCLUDE_DIRS ".")

Re: Multiple source codes cannot be built

Posted: Wed Feb 19, 2025 11:42 pm
by Hiroki
Thanks for the reply.
The information I am getting seems to be correct.
I will try with reinstalling ESP-IDF and VSCode or try with another PC.

Re: Multiple source codes cannot be built

Posted: Thu Mar 06, 2025 1:04 am
by Hiroki
Hello.
I'm sorry for the delay, but I tried on another PC.
As a result, I was able to build correctly with the same source code.
I can't pinpoint the cause, but it may be something wrong with the PC or with the development tools.
Thanks to all who have commented on this issue.