espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.23k stars 7.18k forks source link

Renaming and moving main component and adding a component makes main component not compile anymore (IDFGH-4567) #6384

Closed ToBoMi closed 3 years ago

ToBoMi commented 3 years ago

Environment

Problem Description

When the main component is renamed (moved to a subfolder) and another component is created, the main component is not compiled anymore resulting in undefined reference to `app_main'

Expected Behavior

main is compiled and app_main function is found

Actual Behavior

main is not compiled and app_main function is not found

Steps to reproduce

  1. Create an empty project using eclipse "New esspressif project" wizard
  2. Compile and find it compiles fine
  3. Move main component to source/startup and rename the main component according to the docs
  4. Comile and check that it it compiles fine
  5. Add another component to source/testComponent
  6. Compile and see it doesn't compile

I've created a test project in a git repository that holds the history made in the steps mentioned above:

Code to reproduce this issue

renamingMainAddingComponent.zip

Debug Logs

build log is in the attached git repository.

Other items if possible

ToBoMi commented 3 years ago

If an additional component is created while the main component is located in the standard location: projectDir/main the main component compiles fine.

Alvin1Zhang commented 3 years ago

Thanks for reporting.

projectgus commented 3 years ago

Hi @TobiasBoeschMiele,

Thanks for the comprehensive explanation of the problem, and the test project.

In CMake, EXTRA_COMPONENT_DIRS is a variable. It's set in the CMakeLists.txt file, and then read inside the implementation of project.

So when doing this in the top-level CMakeLists.txt file:

set(EXTRA_COMPONENT_DIRS "./source/startup")                                                                                         
set(EXTRA_COMPONENT_DIRS "./source/testComponent")                                                                                   

The second statement replaces the value of EXTRA_COMPONENT_DIRS with the new value, the old value is not saved anywhere.

You can set the variable to a list of values in multiple ways. For example, this can work:

set(EXTRA_COMPONENT_DIRS "./source/startup" "./source/testComponent")                                                                                   

However, would recommend doing this instead:

set(EXTRA_COMPONENT_DIRS "source")

The build system will automatically look in every subdirectory of source for a component CMakeLists.txt file.

ToBoMi commented 3 years ago

Thanks @projectgus. Not overwriting the previous value of EXTRA_COMPONENTE_DIRS solves the problem. The reason I used EXTRA_COMPONENT_DIRS that way might be that REQUIRES behaves that way.

REQUIRES foo
REQUIRES bar