I have a new project created with PlatformIO in CLion. I've copied the Servo-1.1.8 library into the include directory.

#include <Arduino.h>
#include "Servo-1.1.8/src/Servo.h"

Servo servo;

void setup() {

void loop() {

I'm getting a compilation error though:

====================[ Build | Production | uno ]================================
C:\Users\USER_NAME\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\213.5744.254\bin\cmake\win\bin\cmake.exe --build C:\Users\USER_NAME\Documents\Arduino\MultiServoCallibration\cmake-build-uno --target Production
[1/1] cmd.exe /C "cd /D C:\Users\USER_NAME\Documents\Arduino\MultiServoCallibration && platformio -c clion run -euno"
FAILED: CMakeFiles/Production C:/Users/USER_NAME/Documents/Arduino/MultiServoCallibration/cmake-build-uno/CMakeFiles/Production 
cmd.exe /C "cd /D C:\Users\USER_NAME\Documents\Arduino\MultiServoCallibration && platformio -c clion run -euno"
Processing uno (platform: atmelavr; board: uno; framework: arduino)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (3.4.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
 - framework-arduino-avr 5.1.0 
 - toolchain-atmelavr 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\uno\src\main.cpp.o
Linking .pio\build\uno\firmware.elf
C:\Users\USER_NAME\AppData\Local\Temp\ccmN7v6f.ltrans0.ltrans.o: In function `_GLOBAL__sub_I_servo':
<artificial>:(.text.startup+0x98): undefined reference to `Servo::Servo()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1
========================== [FAILED] Took 1.18 seconds ==========================
ninja: build stopped: subcommand failed.

I've never used CMake before, so it might well be something super simple like adding a line to some config to include that library.

  • 1
    the Servo.cpp file is not compiled
    – Juraj
    Commented Dec 9, 2021 at 16:20
  • @Juraj Aye. If I comment out the Servo servo; line then it compiles. It's not very useful without it though.
    – BanksySan
    Commented Dec 9, 2021 at 16:30

1 Answer 1


For what it's worth, I asked a similar question on StackOverflow, on the chance that the slightly different crowd might include someone who uses CLion + PlatformIO for non-Arduino embedded work and has a more authoritative opinion on the topic.

I have no idea whether it's actually safe or a good idea, but for what it's worth, I was able to add an Arduino library to my project by doing the following:

  1. Install PlatformIO with bundled VS Code, install CLion, then configure CLion to use PlatformIO.
  2. Using CLion, create a new PlatformIO Arduino sketch. Let CLion spin its wheels, do some things that might or might not have ultimately made a difference, and make sure it's in a state where it can build and deploy successfully using CLion. I personally just called Serial.start(9600) and Serial.println("something") to output to serial, then verified it actually worked.
  3. Exit CLion, and launch VS Code. Add the folder containing the sketch created in step 2 to its workspace.
  4. Use VS Code to add the library. Wait for it to finish downloading, and exit VS Code.
  5. Relaunch CLion, and try to use the new library.

Be warned, I have absolutely no idea yet whether or not this is actually kosher. I'm under the impression that when you're using PlatformIO with CLion, 100% of everything is actually managed by PlatformIO, and all CLion itself does is stub through the call to launch CMake. Assuming VS Code is the same way, this should theoretically be OK... but until someone intimately familiar with PlatformIO and the way it integrates with both CLion and VS Code reassures me that it is, I'm a little bit nervous about it.

That said... if it actually is safe to do, it's probably the best way to add an Arduino library to a CLion-PlatformIO project since (AFAIK) CLion itself has absolutely no comparable functionality (via the PlatformIO plugin or otherwise), and I've encountered a few libraries for SSD1306 OLED use that are a major pain to copy into a project by hand from their Github repo (because the OLED library has dependencies on somebody else's graphics library, which itself has dependencies on somebody else's math library and menu library, the menu library has dependencies on one or two more libraries... well, you get the idea. Pain. The exact reason things like Gradle and Maven exist for Android & Java, and CMake theoretically now exists for C(++), even though it still seems to be pretty useless in Arduino-land. ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.