arduino-cmake / Arduino-CMake-NG

CMake-Based framework for Arduino platforms
MIT License
138 stars 39 forks source link

FastLED library linker errors #82

Open KevinRhyne opened 5 years ago

KevinRhyne commented 5 years ago

Hi,

I'm trying to use the FastLED library with Arduino-CMake-NG and getting linker errors while attempting to link FastLED.

My make output:

[ 80%] Built target nano_atmega328_core_lib
[ 83%] Built target fast_led
[ 87%] Linking CXX executable Rhyne_LED.elf
/var/folders/_3/m56nwyn16qq5wmyny1ntss940000gn/T//ccZwq6tt.ltrans0.ltrans.o: In function `__base_ctor ':
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/controller.h:67: undefined reference to `CLEDController::m_pHead'
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/controller.h:67: undefined reference to `CLEDController::m_pHead'
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/controller.h:67: undefined reference to `CLEDController::m_pHead'
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/controller.h:67: undefined reference to `CLEDController::m_pHead'
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/controller.h:68: undefined reference to `CLEDController::m_pTail'
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/controller.h:68: undefined reference to `CLEDController::m_pTail'
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/controller.h:69: undefined reference to `CLEDController::m_pTail'
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/controller.h:69: undefined reference to `CLEDController::m_pTail'
/var/folders/_3/m56nwyn16qq5wmyny1ntss940000gn/T//ccZwq6tt.ltrans0.ltrans.o: In function `addLeds':
/Users/rhyne/workspace/arduino/rhyne-led/lib/FastLED/FastLED.h:305: undefined reference to `CFastLED::addLeds(CLEDController*, CRGB*, int, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [Rhyne_LED.elf] Error 1
make[1]: *** [CMakeFiles/Rhyne_LED.dir/all] Error 2
make: *** [all] Error 2

My CMakeLists.txt is as follows:

cmake_minimum_required(VERSION 3.8.2)

project( Rhyne_LED LANGUAGES C CXX )

get_board_id( board_id nano atmega328 )

file(GLOB SOURCES "src/*.cpp")
file(GLOB HEADERS "src/*.h")

add_arduino_executable( Rhyne_LED ${board_id} ${SOURCES} ${HEADERS})

add_arduino_library(fast_led ${board_id} lib/FastLED/FastLED.h)
link_arduino_library(Rhyne_LED fast_led ${board_id})

My main.cpp is as follows:

#include <FastLED.h>
#define DATA_PIN 6
#define NUM_LEDS 256

void loop() {}

CRGB leds[NUM_LEDS];

void setup() {
    FastLED.addLeds<WS2812B, DATA_PIN>( leds, NUM_LEDS );
}

Apologies in advance if this is due to my limited understanding of project structure. Any help would be greatly appreciated! Thank you!

OS: macOS OS Version: High Sierra Platform: Arduino Nano atmega328 Platform SDK Version: 1.8.9

MrPointer commented 5 years ago

@KevinRhyne Hi there, apologies for the delay. I can detect a few problems with your cmake config which are causing issues:

  1. Don't ever use the pattern file(GLOB SOURCES "src/*.cpp") to add sources/headers to a target. This is described in detail at the cmake docs. Instead, list all of your sources manually.
  2. When you've added the library FastLED, you did it manually using add_arduino_library. You can use find_arduino_library which is supposed to be far more convenient, however this is not a requirement as it might not work under some circumstances.
  3. Given that you're still using the manual method of add_arduino_library - You've specified only the header file of the library as the sources of the library, but this library also has other sources (mainly FastLED.cpp) which have to be included. This is described in detail in our wiki.

I hope that's enough to get you going! Please update if that indeed solved your problems and feel free to continue and ask questions 😄