PlatformIO Community

CLion Arduino .ino files are not recognised by the "init" command

I’ve tried to follow the documentation for setting up a CLion project, but I can’t get it to work.

I’m on a Mac, and used homebrew to install platformio, and it was upgraded today as part of brew upgrade.

$ brew list platformio
/usr/local/Cellar/platformio/2.11.1/bin/pio
/usr/local/Cellar/platformio/2.11.1/bin/platformio
/usr/local/Cellar/platformio/2.11.1/libexec/bin/ (2 files)
/usr/local/Cellar/platformio/2.11.1/libexec/lib/ (180 files)
/usr/local/Cellar/platformio/2.11.1/libexec/vendor/ (226 files)

My basic summary of steps taken while following the docs – http://docs.platformio.org/en/latest/ide/clion.html

$ mkdir ard_test01
$ cd ard_test01/
$ platformio init --ide clion --board teensy31
The current working directory /Users/home/pyMTS/arduino/ard_test01 will be used for project.
You can specify another project directory via
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
The next files/directories will be created in /Users/home/pyMTS/arduino/ard_test01
platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
src - Put your source files here
lib - Put here project specific (private) libraries
Do you want to continue? [y/N]: y
Project has been successfully initialized!
Useful commands:
`platformio run` - process/build project from the current directory
`platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board
`platformio run --target clean` - clean project (remove compiled files)
`platformio run --help` - additional information

At this point instructions ask to add source files…

$ cp ../tft_demo/src/demo.ino src/
$ ls src
demo.ino

Now I open CLion. The docs say to do “Menu: File > Import Project”, but when there are no projects open, the splash screen import option reads “Import Project from Sources”.

I navigate to the project directory and select it – /Users/home/pyMTS/arduino/ard_test01

Just to confirm that it has the ini file there

$ ls  /Users/home/pyMTS/arduino/ard_test01
CMakeLists.txt		CMakeListsPrivate.txt	lib			platformio.ini		src

Now CLion complains that the the import is blocked by an existing CMakeLists.txt file…

At this point, it appears the Import action is not valid on the platformio project… so I’ll try each option.

First “Open Project”

CLion opens a project window, shows platformio.ini and complains in the “CMake” pane:

Error:add_executable called with incorrect number of arguments

I hit F4 to navigate to the source of the error, and it show the last line of CMakeLists.txt

add_executable(${PROJECT_NAME} ${SRC_LIST})

If I just ignore the error, the next step in the docs is to open a source file and build… so I open src/demo.ino and do “Menu: Run > Build”. That brings up the Run/Debug window, and it has an Error: Target ‘PLATFORMIO_BUILD(and_test01)’ not found.

I guess that’s related to the preceding “add_executable” error from earlier?

So, I try an initialise a new project to try the “overwrite” option when trying to import the project…

$ cd ..
$ mkdir ard_test02
$ cd ard_test02
$ platformio init --ide clion --board teensy31
The current working directory /Users/home/pyMTS/arduino/ard_test02 will be used for project.
You can specify another project directory via
`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.
The next files/directories will be created in /Users/home/pyMTS/arduino/ard_test02
platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
src - Put your source files here
lib - Put here project specific (private) libraries
Do you want to continue? [y/N]: y
Project has been successfully initialized!
Useful commands:
`platformio run` - process/build project from the current directory
`platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board
`platformio run --target clean` - clean project (remove compiled files)
`platformio run --help` - additional information
$ cp ../tft_demo/src/demo.ino src/

Switch to CLion, Import Project from Sources, select ard_test02, and this time choose “Overwrite CMakeLists.txt”

I tick the boxes for including the “lib” and “src” project directories, and then OK.

The project window opens on CMakeLists.txt, and the CMake pane is showing two errors and a few warnings…

CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.5)
project(ard_test02)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES
    lib/readme.txt
    src/demo.ino)
add_executable(ard_test02 ${SOURCE_FILES})

And the errors/warnings:

Where did I go wrong? How can I achieve a CLion IDE integration that lets me follow dependencies and have code completion etc?

As a side note, the demo.ino sketch will build and upload from the CLI…

$ platformio run --target upload
[Tue Jul 12 22:11:30 2016] Processing teensy31 (platform: teensy, board: teensy31, framework: arduino)
.. snip ..
Teensy Loader, Command Line, Version 2.0
Read ".pioenvs/teensy31/firmware.hex": 23712 bytes, 9.0% usage
Soft reboot is not implemented for OSX
Waiting for Teensy device...
(hint: press the reset button)

And this is my CLion install, from “Menu : CLion > About CLion”

CLion 2016.1.3
Build #CL-145.1617, built on June 7, 2016
JRE: 1.8.0_76-release-b198 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  1. :moneybag: Thanks a lot for your donation!!! :moneybag:
  2. I’ve just updated documentation for CLion IDE:

https://github.com/platformio/platformio/commit/ba234754253f163d8227ef7fd667b3f9c95d272c

Could you use *.cpp instead *.ino?

You’re very welcome. I’m hoping it helps keep up the stellar support for the system!

I was hoping to avoid moving the setup() and loop() functions below all the helper functions, but this will work for now.

Does this also break compatibility with the regular Arduino IDE?

You don’t need to move code. Just declare prototypes before theirs first call. For example


void my_func();

// some code

void setup() {
}

void loop() {
}

void my_func () {
  // implementation
}

You can create empty “void.c” file and continue to use INO format :slight_smile: However, you will not have code completion and code linting.

If you are going to create Arduino library, then you SHOULD use only CPP/C. If you talk about Arduino project… Yes, Arduino IDE requires INO file that should have the same name as a main sketch. I don’t know who invented these wheels…

Hey gang! I’m having the precisely same issue, and I didn’t see how it was resolved in this thread. I used to have a related issue, that appears to have been been resolved by removing spaces in the folder name. But currently, I’m stuck with the above “Error:CMake can not determine linker language for target: ___”

I got the same results as above when trying the “Open Project” in the Import Project dialog. For what it’s worth, I followed all the documentation accurately. All my files are cpp / h, no ino files. If you need more info, let me know. Thanks!

Try to switch to development version http://docs.platformio.org/en/latest/installation.html#development-version

Then, don’t forget to re-init project with pio init --ide clion. Did it help?

Yep, that seems to have done it. Thanks!

Hello, I am facing the same issue. Using teensy31 and Clion, I don’t have any build configuration in my IDE which works for me, even when I overwrite the CMakeLists.txt (after importing the project). Switching to the pio development branch doesn’t help either. So what’s the solution for that problem? Is it an issue of pio or just a mistake of mine? Thank you.

Are you on Windows? Try to search for other “clion” related topics here. We have a lot of solutions.

@ivankravets Yes, I am on windows 10 and using Clion 2016.2.3. I tried all given solutions I found in this forum: switching to the development branch, overwriting the CMakeList.txt, using another MinGW release. Nothing helps :frowning:

The two errors I get:

Error:aux_source_directory called with incorrect number of arguments
Error:add_executable called with incorrect number of arguments

When I run pio on the command line everthing seems fine, just the IDE integrations is a problem.

Do you have source files c/c++ in src directory?

Yes, I have some *.h and some *.c files in the src folder.

@averri do you have any ideas? You had the same problem on a Windows.

Oh, I just solved the issue by accident. The absolute path to the project directory included whitespace. After renaming some folder, the tool chain works. Thank you for your help!

It looks like a bug. Path should be escaped. Could you play to escape it and report here what we should to do while generate a CLion project?

I did the following:

  1. Create a folder with a name with whitespace: “Play Machine”
  2. run pio init --ide clion --board teensy31
  3. Put some src files and a library in the folder.
  4. Import the project to Clion.

Now, in my configuration the error occurs.

You may create a bug on Jetbrains, project CLion: https://youtrack.jetbrains.com/issues

It looks like CLIon/CMake issue. Please check “CMakeLists.txt” file and the last line where PlatformIO Project Generator speicifes path to source files. I’ve tried to escape this path in multiple ways: “Play\ Machine” and put it between quotes. These don’t work for me.

Pelase contact with CLion support and report here any news. Thanks.

Hi @ivankravets, “All CLion/PlatformIO Teams”, thank you very much for all effort with Clion and PlatformIO. I very appreciate with Clion tool that it took me ability to learn now quite big codebase (project Tasmota). I’m not c/cpp developer, I’m from java world. And Clion helps me learn many language things just on the fly and here. Just loved Clion for that! :rocket:

I have a question. Project tasmota contains many *.ino files. Clion and PlanformIO importer work fine - I can navigate by code in some bounds. But Clion still not fully support *.ino projects, and some for some types I couldn’t jump go to the declaration or view inferred type. Exactly because *.ino does have necessary includes.

But as found, that during compilation I’ve got big .ino.cpp file with all necessary declarations. Exactly how compiler look this codebase before compile.

My question next.
Is there any way/workaround using this .ino.cpp file/files as “reference” i.e. for jumping to declaration and for help to Clion infer types? It is possible somehow? At least just for navigating and help in code?