Error: Couldn't find the main target of the project!

Long time user of the ESP IDF, using their python scripts etc to build. Decided to make the leap to using platformio.

I have a project, which compiles fine from the command line with idf.py build but platformio is throwing me the error Error: Couldn't find the main target of the project!

The project structure is slightly different than the norm:

  • Inside the project dir, there is a folder called “core” which houses two other folders, “Src” and “Inc”. Where “Src” houses main.cpp. The “core” component is registered in the “CMakeLists.txt” file in this “core” folder.
  • Inside the project dir there is another folder called “application” which houses several folders which are setup as components, each with their own `CMakeLists.txt"

My platformio.ini is, and where I think my error must be:

[platformio]
src_dir = core/Src
[env]
platform = espressif32
framework = espidf
platform_packages = framework-espidf
[env:fm-devkit]
board = fm-devkit

And the terminal log:

Executing task in folder esp32: C:\Users\Simon.platformio\penv\Scripts\platformio.exe run <
Processing fm-devkit (board: fm-devkit; platform: espressif32; framework: espidf)
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Espressif 32 1.12.0 > ESP32 FM DevKit
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-espidf 3.40000.200303 (4.0.0)
  • tool-cmake 3.16.5
  • tool-esptoolpy 1.20600.0 (2.6.0)
  • tool-idf 1.0.1
  • tool-mconf 1.4060000.20190628 (406.0.0)
  • tool-ninja 1.9.0
  • toolchain-esp32ulp 1.22851.190618 (2.28.51)
  • toolchain-xtensa32 2.80200.200226 (8.2.0)
    Reading CMake configuration…
    Error: Couldn’t find the main target of the project!
    ======================================================================================== [FAILED] Took 14.60 seconds ========================================================================================
    The terminal process terminated with exit code: 1
    Terminal will be reused by tasks, press any key to close it.

EDIT: Formatting

Have you tried src_dir = core?

yep, same result I’m afraid

Same exact issue here. Any solutions here?

Try following the folder structure exactly as outlined in the documentation. If you have this structure and it still not works, make sure you’re running all the latest version (PIO core and platforms). If it still doesn’t work, upload the project so that the problem can be reproduced by a developer.

It might the case that src_dir doesn’t really work because the ESP-IDF is such a special CMake based buildsystem and bypasses a lot of the normal PlatformIO functionality so folders have to be in their normal expected place. Maybe @valeros can comment on this folder structure here.

I am receiving the exact same error message, even with a newly generated project, generated with PIO. As point of interest, that project also will not build using idf.py build, throwing the same error.

Looks like a possible bug when a custom src_dir is used, please open an issue here GitHub - platformio/platform-espressif32: Espressif 32: development platform for PlatformIO

Issue opened - Error: Couldn’t find the main target of the project! · Issue #330 · platformio/platform-espressif32 · GitHub
Many thanks everyone.

In may case it happened when I chnged the monitor com port in the platformio.ini.
It was building ok I changed the monitor com port in the platformio.ini.
I rearrange the platformio.ini in the aspect to comment and descomment some lines forcing the file to be rebuilt and restarts working properly!!!
I do not found the real reason!
My cents …

Same issue here after changing com port. Error was:
Error: Couldn’t find target config target-Project.elf-c8fe39aa9c40e5860eb9.json
I followed joakuim path and the issue resolved itself!

I just experienced the same problem @barryrroberts and @joakuim described. Was using the monitor to work with the ESP and at one point I unplugged and reattached the device without removing the FTDI from the computer and the FTDI reenumerated which I thought was kind of odd. Then when I changed the .ini file the error occurred. Cleaning the build didn’t fix it but editing the .ini fixed the problem.

I also just faced the same error, this might due to building requirements, You can rebuild your project after cleaning the existing build files.

Clean Build Files: pio run --target clean
Build: pio run
flash: pio run --target upload

Might this work for you also. Happy Hacking.

1 Like