I am using CLion. I created a new project for an Arduino example that I’m following. I created the project using this command:
platformio init --ide clion --board megaatmega2560 --project-dir my-dir
I have included a library in the
lib/ directory and put the header file in the
include/ directory. Here is my project structure:
. ├── CMakeLists.txt ├── CMakeListsPrivate.txt ├── cmake-build-debug │ └── CMakeFiles ├── cmake-build-megaatmega2560 │ ├── CMakeCache.txt │ ├── CMakeFiles │ ├── Makefile │ ├── cmake_install.cmake │ └── proximity-alarm.cbp ├── include │ ├── README │ └── SR04.h ├── lib │ ├── README │ ├── SR04.cpp │ └── SR04.h ├── platformio.ini ├── src │ └── proximity_alarm.cpp └── test └── README
I opened this project in CLion and have run “Reload CMake Project” a few times.
proximity_alarm.cpp, I am including the library like this:
#include <Arduino.h> #include <SR04.h> # other code
When I build, I am getting this error:
/var/folders/5f/q429hvss3w5cymp2m3dk_31c0000gp/T//cc0yW322.ltrans2.ltrans.o: In function `global constructors keyed to 65535_0_proximity_alarm.cpp.o.1900': <artificial>:(.text.startup+0x64): undefined reference to `SR04::SR04(int, int)'
Originally for this project, I used
pio to install this library like this:
pio lib install --save lib/HC-SR04/
But that installed the library to some mysterious
.pio directory and I would rather avoid having to run a command to install libraries for my projects, and I would rather rely on dropping files in
lib/, which is why I recreated this project and am trying to debug why the
lib/ directory is not working as expected.
proximity_alarm.cpp code is unchanged, I know that it works when the
SR04 library is on the path/linked/whatever correctly. I’m trying to understand why it’s not being found - I was expecting the
pio project to bootstrap the lib include paths for the
I have read this question and answers: https://github.com/platformio/platformio-core/issues/273
I have tried this lib structure, but a failure still occurs:
├── lib │ ├── README │ └── SR04 │ ├── SR04.cpp │ └── SR04.h
And I think I’m doing what it says, but it still doesn’t compile Do I need to configure anything else (like the ini or CMakeList file)?
I see this library in my ‘External Libraries’ section:
When I ‘reveal’ the location of that library it is pointing to my
lib/SR04/* path, which I think is good, but I am still perplexed as to why it wont compile.