Add library to CLion project

已完成

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)
PACKAGES:
- 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 or CLion before, so it might well be something super simple like adding a line to some config to include that library.

 

3

David Banks

  1. Make sure the Servo library is installed in your development environment.
  2. You need to tell CMake how to find the library. If you're lucky, the library installs config files that let you use find_package(). If not, you can try find_library().
  3. You need to tell CMake to add the library to your executable using target_link_libraries().

The CMake Tutorial is pretty good for showing you the basics.

 

0

Michael Klatt platform IO is the build tool .. there would be no point in using cmake in the first place. so this answer is not good enough. but I get it .. it seems this is the only savagely way to get the library into clion. I didn't know how bad this tool actually is. @Jetbrains  make it BETTER!

---- 
after trying it out with v2022 I upgraded to v2023 (which should not be necessary)
this offered me upgradeable pio plugins 
however this hoop wasnt the last to jump 
I also had to delete idea folder, open the ini file solitarily to have the plugins updated 
loading the project again 
and reload platform io project .. 
then add a run configuration without before lunch and 
update the tooling … srsly?!
 

0

请先登录再写评论。