PicoLED
PicoLED copied to clipboard
undefined reference to `PicoLed::PicoLedController ... `
Hello, I'm trying to include this library in my project. Following the setup instructions i've added the cmake file in my CMakeLists.txt like so:
cmake_minimum_required(VERSION 3.12)
# Pull in PICO SDK (must be before project)
include(pico_sdk_import.cmake)
include("PicoLed/PicoLed.cmake")
Which configured without error, then i try including the .hpp file into my file (i'm using hello_multicore.cpp as a starting point)
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "PicoLED/PicoLed.hpp"
( ..... )
int main() {
auto ledStrip = PicoLed::addLeds<PicoLed::WS2812B>(pio0, 0, 0, 55, PicoLed::FORMAT_GRB);
( .... )
}
but this results in an error
[build] [ 18%] Linking CXX executable hello_multicore.elf
[build] /opt/homebrew/Cellar/arm-none-eabi-gcc/10.3-2021.07/gcc/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/hello_multicore.dir/multicore.cpp.obj: in function `PicoLed::PicoLedController PicoLed::addLeds<PicoLed::WS2812B>(pio_hw_t*, unsigned int, unsigned int, unsigned int, PicoLed::DataByte, PicoLed::DataByte, PicoLed::DataByte, PicoLed::DataByte)':
[build] /Users/nathanielclaflin/pico-examples/multicore/hello_multicore/PicoLED/PicoLed.hpp:36: undefined reference to `PicoLed::WS2812B::WS2812B(pio_hw_t*, unsigned int, unsigned int, unsigned int, PicoLed::DataByte, PicoLed::DataByte, PicoLed::DataByte, PicoLed::DataByte)'
[build] /opt/homebrew/Cellar/arm-none-eabi-gcc/10.3-2021.07/gcc/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /Users/nathanielclaflin/pico-examples/multicore/hello_multicore/PicoLED/PicoLed.hpp:38: undefined reference to `PicoLed::PicoLedController::PicoLedController(std::shared_ptr<PicoLed::PicoLedTarget>)'
[build] /opt/homebrew/Cellar/arm-none-eabi-gcc/10.3-2021.07/gcc/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/hello_multicore.dir/multicore.cpp.obj: in function `main':
[build] /Users/nathanielclaflin/pico-examples/multicore/hello_multicore/multicore.cpp:36: undefined reference to `PicoLed::PicoLedController::~PicoLedController()'
[build] /opt/homebrew/Cellar/arm-none-eabi-gcc/10.3-2021.07/gcc/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /Users/nathanielclaflin/pico-examples/multicore/hello_multicore/multicore.cpp:36: undefined reference to `PicoLed::PicoLedController::~PicoLedController()'
would appreciate any ideas, thanks!
Hey @claflinnate - I'm an absolute noob to CMake, Pi Pico and mostly to C++ even... but I ran into the very same issue, and I think your problem is you didn't include PicoLed as a library. The key bits are:
In your main cpp make sure to include PicoLed.hpp
with angled brackets:
#include <PicoLed.hpp>
and in CMakeLists.txt:
set(PICO_CXX_ENABLE_EXCEPTIONS 1) # Required by PicoLed.hpp:31
...
pico_sdk_init()
...
include("PicoLed/PicoLed.cmake")
...
target_link_libraries(yourBinaryName pico_stdlib PicoLed)
The thing I missed was that target_link_libraries
must include PicoLed
as well!