Encountering unknown CMake command "idf_component_register"

User avatar
Micrified
Posts: 11
Joined: Thu Aug 29, 2019 1:26 pm

Encountering unknown CMake command "idf_component_register"

Postby Micrified » Thu Aug 29, 2019 1:39 pm

After downloading and building the ESP32 repository for Linux (I am running elementary OS 4.0 Juno), I've encountered a problem where I can't invoke anything to do with `idf.py`. I can't call `menuconfig`, or flash/monitor examples. I consistently get the error:

```
CMake error at main/CMakeLists.txt:1 (idf_component_register):
Unknown CMake command "idf_component_register
```

If I google the problem, I get this one github thread here: https://github.com/espressif/esp-idf/issues/3741

And the user in question "solved" his problem (which isn't entirely the same as mine) by refactoring his code into fewer files. In any case, it doesn't reapply apply since he has a different issue (he can use menuconfig sometimes) and the solution isn't ideal.

Can anyone explain to me how to solve this problem?
Micrified (Netherlands)

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Encountering unknown CMake command "idf_component_register"

Postby ESP_Angus » Fri Aug 30, 2019 2:29 am

Hi Micrified,

What version of ESP-IDF do you have? "idf_component_register" was only added in ESP-IDF V4.0 so older versions use different syntax. The IDF Programming Guide that matches the version you are using should have the correct syntax.

If this isn't the problem, can you please post the full output from running idf.py against one of the included examples?

Thanks,


Angus

User avatar
Micrified
Posts: 11
Joined: Thu Aug 29, 2019 1:26 pm

Re: Encountering unknown CMake command "idf_component_register"

Postby Micrified » Fri Aug 30, 2019 12:39 pm

Hello. Let me explain what I did to install it. I in fact went right back through the procedure to make sure:

1. I first began by installing the standard toolchain for Linux. The guide I link here is what I followed: https://docs.espressif.com/projects/esp ... setup.html.

I installed it for 64-bit Linux. Everything is fine. I unzipped the toolchain to the recommended directory at ~/esp.
My shell profile currently looks as follows after modifying it:
[Codebox]
export IDF_PATH=~/esp/esp-idf
export PATH=~/esp/xtensa-esp32-elf/bin:$PATH
[/Codebox]

2. I continued with the rest of the guide here: https://docs.espressif.com/projects/esp ... et-esp-idf to get the ESP repository. This was just fine.

3. I added the tools to the path using: . add_path.sh

In my personal project, I encounter the same error I described as before if I invoke: idf.py build

[Codebox]
Came Error at main/CMakeLists.txt:1 (idf_component_register):
Unknown CMake command "idf_component_register".
[/Codebox]


Of course, the guide is using make instead. If I try to compile my program with make, then it works, but I get errors that don't exist on my Linux workstation at home (this isn't compiling on a Linux laptop). For instance:

[Codebox]
/home/micrified/esp/esp32-wifi/build/libmain.a(esp32_wifi_main.o):(.literal.app_main+0x14): undefined reference to `ble_init`
[/Codebox]

This doesn't make any sense, because (well it works on another workstation) and the header defining that function is clearly accessible and reachable:

Project Structure:
[Codebox]
- main
| - include
| | - ble.h
| | - ble_profiles.h
| | - wifi.h
| - src
| | - ble.c
| | - wifi.c
- CMakeLists.txt
- component.mk
- esp_32_wifi_main.c
[/Codebox]
(These files are very small)
See esp_32_wifi_main.c here: https://gist.github.com/Micrified/ec855 ... 08e5b92766
See ble.h here: https://gist.github.com/Micrified/4f9e9 ... 67ffe66aa0
See ble.c here:https://gist.github.com/Micrified/0145a ... 0e4aeeee03

If you can help me figure out what on Earth is going on I'd be very grateful.
Micrified (Netherlands)

Junior
Posts: 3
Joined: Sat Sep 07, 2019 7:23 am

Re: Encountering unknown CMake command "idf_component_register"

Postby Junior » Sun Sep 22, 2019 6:21 am

ESP_Angus wrote:
Fri Aug 30, 2019 2:29 am
Hi Micrified,

What version of ESP-IDF do you have? "idf_component_register" was only added in ESP-IDF V4.0 so older versions use different syntax. The IDF Programming Guide that matches the version you are using should have the correct syntax.

If this isn't the problem, can you please post the full output from running idf.py against one of the included examples?

Thanks,


Angus
Thanks. This solved it for me. I was cloning the wrong branch. V4.0 > (latest) is required.

akhilaki46784
Posts: 1
Joined: Wed Jun 16, 2021 4:42 pm

Re: Encountering unknown CMake command "idf_component_register"

Postby akhilaki46784 » Wed Jun 16, 2021 4:46 pm

change idf_component_register() in CMakeLists.txt to register_component().
Now try "idf.py build"

Germanunkol
Posts: 3
Joined: Sun Aug 21, 2022 6:27 pm

Re: Encountering unknown CMake command "idf_component_register"

Postby Germanunkol » Sun Sep 04, 2022 7:18 pm

Sorry for re-opening this old thread, but I found it while having the same error:

It can also happen if you're trying to build in the wrong folder. In my case, I was calling

Code: Select all

idf.py build
inside the component folder instead of its parent. Switching to the correct folder before building solves the issue.

mihvoi
Posts: 2
Joined: Sat Mar 09, 2024 2:41 pm

Re: Encountering unknown CMake command "idf_component_register"

Postby mihvoi » Sat Mar 09, 2024 2:59 pm

I has a similar problem, that was fixed by... not doing the build in that directory, but in the main project directory.

The below error was happening on a "library" module, where I tried to do idf.py build, receiving
  1. CMake Error at CMakeLists.txt:9 (idf_component_register):
  2.   Unknown CMake command "idf_component_register".
The solution for me was to go to the main directory of the project and directly do idf.py build there, after removing the ./build temporary directory. The project correctly used the dependencies without doing any build for the libraries.

Before finding this solution I searched a lot and found this post. Hope this helps people like me, not sure if all have my issue.

For the reference:
- my project directory where
idf.py build
worked was: M5_Camera_Examples/idf/SMB-PUT
- the error was happening on M5_Camera_Examples/common/i2c_manager - running build here was not needed actually
- I used this for my project to work:
idf.py --version
ESP-IDF v4.4.7
P.S. It helped to remove the ./build temporary directory before the build - in the main directory of the project.

Note: I am noob to this build system, I cannot explain at this moment why this works like this.

Who is online

Users browsing this forum: No registered users and 66 guests