PlatformIO Community

Newly generated espidf project doesn't build in CLion

Hi, I have installed and updated pio, espidf, and CLion. I can create a new project using the PlatformIO plugin, however, building the project fails with “Couldn’t find the main target of the project!”

When I take a look at CMakeLists.txt, it sets empty.c as app source file and I have copied the Blink example to that, as well as to main.c in the same directory. Both lead to the same error.

When I copy the espidf examples and build them using esp.py build, that works so I assume the toolchain works. Using CLion to generate an Arduino project works and can compile. But I’d like to use the espidf framework. I just cannot figure out how to get it running. I’d very much appreciate some help diagnosing the issue. Thanks!

====================[ Build | Debug | esp32doit-devkit-v1 ]=====================
"/Users/joris/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/201.6668.126/CLion.app/Contents/bin/cmake/mac/bin/cmake" --build /Users/joris/Projects/test2/cmake-build-esp32doit-devkit-v1 --target Debug -- -j 12
Processing esp32doit-devkit-v1 (platform: espressif32; board: esp32doit-devkit-v1; framework: espidf)

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32doit-devkit-v1.html
PLATFORM: Espressif 32 1.12.0 > DOIT ESP32 DEVKIT V1
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.4 
 - tool-esptoolpy 1.20600.0 (2.6.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 0.57 seconds 
make[3]: *** [CMakeFiles/Debug] Error 1
make[2]: *** [CMakeFiles/Debug.dir/all] Error 2
make[1]: *** [CMakeFiles/Debug.dir/rule] Error 2
make: *** [Debug] Error 2

Does it, by chance, work when you add

to your platformio.ini and rename the src/ folder to main?

It does get farther along the build! Now it fails with “No SOURCES given to target: Z_DUMMY_TARGET”, but it certainly is an improvement!

Are you sure the main/CMakeLists.txt declares the correct filename(s) of the source files within main/?

Not entirely, in the sense that I have edited that file to point to the main.c file I have in there but nothing else. Should I add other files as my app grows?

# Warning! This code was automatically generated for projects
# without default 'CMakeLists.txt' file.

set(app_sources
	"main.c"
)

idf_component_register(SRCS ${app_sources})

Screenshot 2020-04-18 at 19.47.10

Should be equivalent to what the docs say with idf_component_register(SRCS "main.c").

I’ve noticed you’re using CLion. Since it also uses CMake it might be confused and attempt to compile the sources on its own instead of correctly calling into PlatformIO.

Does the project compile with pio run in the console?

Do you have the PlatformIO CLion Plugin installed or are you using it without it? The selected target in the upper right corner is selectable as “PlatformIO Build”? And you only build it with the Build button, not with the Play button? Maybe project re-init helps (pio init --ide=clion in the project folder)?

Thanks for your reply! pio run also doesn’t work unfortunately. I do have the official Pio plugin installed. I am clicking the Build button to the left of the run configuration. Interestingly, I do not have a “PlatformIO Build” run config, only “PlatformIO Debug” or “PlatformIO Upload”.Screenshot 2020-04-18 at 20.16.11

Processing esp32doit-devkit-v1 (platform: espressif32; board: esp32doit-devkit-v1; framework: espidf)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32doit-devkit-v1.html
PLATFORM: Espressif 32 1.12.0 > DOIT ESP32 DEVKIT V1
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.4 
 - tool-esptoolpy 1.20600.0 (2.6.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...
-- The C compiler identification is AppleClang 11.0.3.11030032
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done

CMake Error at CMakeLists.txt:33 (add_executable):
  No SOURCES given to target: Z_DUMMY_TARGET


CMake Generate step failed.  Build files cannot be regenerated correctly.

======================================================================================= [FAILED] Took 1.19 seconds =======================================================================================```

What’s the exact error when running pio run? The above? Because that looks like CLion is trying to reload the project.

How is it possible that this has 33 lines? The docs say a minimal CMakeList.txt at the root of the project with

# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16.0)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(project-name)

suffices.

Ohhh. That’s a tricky one.

The CLion project file generator will of course generate its own CMakeLists.txt which instruct CLion to call into PlatformIO, but PlatformIO for ESP-IDF also needs a CMakeLists.txt with the ESP-IDF configuration code. So if you do pio init --ide=clion you overwrite that… Not sure how a ESP-IDF CMakeLists.txt plus PIO Wrapper CMakeLists.txt should work together.

Can you try replace the root-level CMakeListst.txt with the code given above (from the docs) and retry with just pio run?

That does change the error again.

$ pio run
Processing esp32doit-devkit-v1 (platform: espressif32; board: esp32doit-devkit-v1; framework: espidf)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32doit-devkit-v1.html
PLATFORM: Espressif 32 1.12.0 > DOIT ESP32 DEVKIT V1
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.4
 - tool-esptoolpy 1.20600.0 (2.6.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...
-- Project is not inside a git repository, or git repository has no commits; will not use 'git describe' to determine PROJECT_VER.
-- Project version: 1
-- Building ESP-IDF components for target esp32
-- Checking Python dependencies...
Python requirements from /Users/joris/.platformio/packages/framework-espidf/requirements.txt are satisfied.
-- Configuring incomplete, errors occurred!
See also "/Users/joris/Projects/test2/.pio/build/esp32doit-devkit-v1/CMakeFiles/CMakeOutput.log".
See also "/Users/joris/Projects/test2/.pio/build/esp32doit-devkit-v1/CMakeFiles/CMakeError.log".

fatal: not a git repository (or any of the parent directories): .git
/usr/local/Cellar/platformio/4.3.1/libexec/lib/python3.8/site-packages/pkg_resources/py2_warn.py:22: UserWarning: Setuptools will stop working on Python 2
************************************************************
You are running Setuptools on Python 2, which is no longer
supported and
>>> SETUPTOOLS WILL STOP WORKING <<<
in a subsequent release (no sooner than 2020-04-20).
Please ensure you are installing
Setuptools using pip 9.x or later or pin to `setuptools<45`
in your environment.
If you have done those things and are still encountering
this message, please comment in
https://github.com/pypa/setuptools/issues/1458
about the steps that led to this unsupported combination.
************************************************************
  sys.version_info < (3,) and warnings.warn(pre + "*" * 60 + msg + "*" * 60)
CMake Error at /Users/joris/.platformio/packages/framework-espidf/components/esp32/project_include.cmake:11 (message):
  Internal error, toolchain has not been set correctly by project (or an
  invalid CMakeCache.txt file has been generated somehow)
Call Stack (most recent call first):
  /Users/joris/.platformio/packages/framework-espidf/tools/cmake/build.cmake:305 (include)
  /Users/joris/.platformio/packages/framework-espidf/tools/cmake/build.cmake:458 (__build_process_project_includes)
  /Users/joris/.platformio/packages/framework-espidf/tools/cmake/project.cmake:337 (idf_build_process)
  CMakeLists.txt:6 (project)



========================== [FAILED] Took 2.06 seconds ==========================

Here is the contents of the CMakeError.log that gets mentioned as well. It doesn’t seem very error-y, but it may be enough to screw up my build somehow.

Checking whether the ASM compiler is GNU using "--version" did not match "(GNU assembler)|(GCC)|(Free Software Foundation)":
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Can you remove that file and retry.

I’ve seen Python 3.8 causing errors and Python 3.7 not, but I’m not sure whether that’s the underlying problem here.

It’s still the system compiler though. In CLion -> Options can you add a new toolchain where cmake and make is standard, but C++ and C compiler are pointing to /Users/joris/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-g++ and xtensa-esp32-elf-gcc respectively and put it in the top position? Though the CLion configuration shoudn’t really affect the PlatformIO execution if pio is executed from the commandilne… So maybe it is the cache file.

It builds! Using pio run, but it builds! And I immediately shot myself in the foot by running pio init --ide clion and attempting to build from CLion, because that now gives the first error again “Couldn’t find the main target of the project!” :man_facepalming:

But not being able to use the CLion plugin seems to kind of defeat the purpose of it.

Huh. I added include($ENV{IDF_PATH}/tools/cmake/project.cmake) to the PlatformIO generated CMakeLists.txt, just above the project() line and it is actually trying to do something useful now:

"/Users/joris/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/201.6668.126/CLion.app/Contents/bin/cmake/mac/bin/cmake" -DCMAKE_BUILD_TYPE=esp32doit-devkit-v1 -G "CodeBlocks - Unix Makefiles" /Users/joris/Projects/test2
-- Found Git: /usr/local/bin/git (found version "2.26.0") 
-- IDF_TARGET not set, using default target: esp32
-- The ASM compiler identification is Clang
-- Found assembler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Project is not inside a git repository, or git repository has no commits; will not use 'git describe' to determine PROJECT_VER.
-- Building ESP-IDF components for target esp32
-- Checking Python dependencies...
The following Python requirements are not satisfied:
click>=5.0
pyparsing>=2.0.3,<2.4.0
pyelftools>=0.22
gdbgui>=0.13.2.0
pygdbmi<=0.9.0.2
Please follow the instructions found in the "Set up the tools" section of ESP-IDF Getting Started Guide
CMake Error at /Users/joris/esp/esp-idf/tools/cmake/build.cmake:271 (message):
  Some Python dependencies must be installed.  Check above message for
  details.
Call Stack (most recent call first):
  /Users/joris/esp/esp-idf/tools/cmake/build.cmake:397 (__build_check_python)
  /Users/joris/esp/esp-idf/tools/cmake/project.cmake:395 (idf_build_process)
  CMakeLists.txt:14 (project)


-- Configuring incomplete, errors occurred!
See also "/Users/joris/Projects/test2/cmake-build-esp32doit-devkit-v1/CMakeFiles/CMakeOutput.log".
See also "/Users/joris/Projects/test2/cmake-build-esp32doit-devkit-v1/CMakeFiles/CMakeError.log".

[Finished]

Somehow it can’t see the installed python libraries, it seems.

Maybe it uses a different Python3 runtime. Pretty sure the PlatformIO one is a virtualenv (so that it doesn’t modify system python packages). Not sure if that’s the right way though.

@valeros, this is an interesting usecase. With CLion as a cmake-based IDE, how can PlatformIO + CLion still be used in e.g. ESP-IDF v4 projects which also use a CMakeLists.txt, which collides with the template that PIO creates when doing pio init --ide=clion? Seems we have a paradox here.

Hi @Hertog_Jan ! Starting with version 4.0, ESP-IDF uses a build system based on CMake. In order to provide more seamless integration we also switched to CMake as the source of build configuration. Unfortunately, there is a conflict between CMakeLists.txt used by ESP-IDF and CMakeLists.txt which we generate for CLion. At the moment we’re working on better integration with CLion without this intermediate “hacky” CMakeLists.txt, but there is no ETA for this feature.

In a nutshell, I’d recommend you to rollback to the previous version of the espressif32 platform, e.g.:

platform = espressif32@1.11.2
3 Likes

Yes, using platform = espressif32@1.11.2 and re-runing pio init fixed the build button!

Just be aware that by rolling that back you are now working with ESP-IDF v3.3.

Hi all,
Any update on this ? I would like to use my clion to build my project. The intellisense of vscode is not as well as the one on clion.

Regards,