Hey Guys,  I'm having issues including FastLED.h inside a library I'm trying to create...

Hey Guys,

I’m having issues including FastLED.h inside a library I’m trying to create… Here are the contents of my files

// example.ino
#include “SnakeGame2.h”
#include “FastLED.h”
CRGB test;
void setup() { }
void loop() { func(test); }

// SnakeGame2.h
#ifndef SNAKEGAME2_H_
#define SNAKEGAME2_H_
#include “FastLED.h”
int func(CRGB);
#endif

// SnakeGame2.c
#include “SnakeGame2.h”
#include “FastLED.h”
int func(CRGB leds) { return 0; }

I get about 40 different errors and I have no idea why :frowning: If I delete the contents of SnakeGame2.c and put them in example.ino everything compiles without issue. I can’t seem to figure out why implementing func() in SnakeGame2.c makes the compiler lose it. I’m assuming it has something to do with including FastLED.h in two separate source files.

Any insight would be sincerely appreciated. Thank you.

here’s a sample the errors.

C:\Program Files (x86)\Arduino\libraries\FastLED/lib8tion.h:642: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
C:\Program Files (x86)\Arduino\libraries\FastLED/lib8tion.h:938: error: conflicting types for ‘random8’
C:\Program Files (x86)\Arduino\libraries\FastLED/lib8tion.h:926: error: previous definition of ‘random8’ was here
C:\Program Files (x86)\Arduino\libraries\FastLED/lib8tion.h: In function ‘random8’:

Try grabbing the 2.1 branch - https://github.com/FastLED/FastLED/archive/FastLED2.1.zip - and then replace C:\Program Files (x86)\Arduino/libraries/FastLED with the new folder. There were some include file things that I fixed in 2.1 that you might be running into.

(Short version, though - it sounds like the compiler isn’t finding the definitions of certain types that we use - when giving errors, starting from the first errors is generally best, because many times later errors are caused or exacerbated by earlier errors).

No luck with 2.1 :frowning: here’s the beginning of the error, it goes on for much longer.

In file included from C:\Program Files (x86)\Arduino\libraries\FastLED21/pixeltypes.h:5,
from C:\Program Files (x86)\Arduino\libraries\FastLED21/controller.h:5,
from C:\Program Files (x86)\Arduino\libraries\FastLED21/FastLED.h:11,
from C:\Program Files (x86)\Arduino\libraries\FastLED21/SnakeGame2.h:4,
from C:\Program Files (x86)\Arduino\libraries\FastLED21\SnakeGame2.c:1:
C:\Program Files (x86)\Arduino\libraries\FastLED21/lib8tion.h:558: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
C:\Program Files (x86)\Arduino\libraries\FastLED21/lib8tion.h:628: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
C:\Program Files (x86)\Arduino\libraries\FastLED21/lib8tion.h:645: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
C:\Program Files (x86)\Arduino\libraries\FastLED21/lib8tion.h:668: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
C:\Program Files (x86)\Arduino\libraries\FastLED21/lib8tion.h:683: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
C:\Program Files (x86)\Arduino\libraries\FastLED21/lib8tion.h:979: error: conflicting types for ‘random8’
C:\Program Files (x86)\Arduino\libraries\FastLED21/lib8tion.h:967: error: previous definition of ‘random8’ was here
C:\Program Files (x86)\Arduino\libraries\FastLED21/lib8tion.h: In function ‘random8’:

What version of arduino are you using to build? (Also - rename the library directory to FastLED - and remove the old FastLED directory if you still have it).

Unfortunately, i’m not sure why you’re seeing these errors - I use FastLED in a library as well as in sketches without problems.

Try adding #if defined(ARDUINO) && ARDUINO >= 100
#include “Arduino.h”
#else
#include “WProgram.h”
#include <pins_arduino.h>
#endif

into SnakeGame2.h

(Also - you shouldn’t be putting the SnakeGame files in the FastLED library directory - they should live in their own library directory)

If you’re still having problems - zip up your code (library and .ino file(s)) and email them to me (danielgarcia at gmail) and I can try getting it setup here and see what’s going on with your code/setup.

What @Daniel_Garcia said.
Also, it is a good idea to keep you custom libraries in your user Arduino libraries folder, rather than under Program Files. So “My Documents\Arduino\libraries”. This will keep them safe if you ever delete/reinstall Arduino IDE, remove the need for Admin privileges to alter folders under Program a Files, and some backup utilities won’t include Program Files.

One other advantage (& possibly disadvantage) to the above is that if you have more than one version of the Arduino IDE installed (e.g. 1.0.x & 1.5.x) your library folder will be shared between them.

For others that are following along - the problem ended up being that the library code file was named SnakeGame2.c - which causes arduino (by way of gcc) to try compiling it as a C file. FastLED is unapologetically C++ - which is why the compiler was eating itself all over.

Renaming the file to SnakeGame2.cpp was enough to make the world happy again.

Happy gcc, Happy LEDs, Happy World!

Unbelievable haha. I’ve been wrestling with this for over a day now absolutely losing my mind thinking I’m in the twilight zone. and all it was was a file extension >_< Really appreciate your time gents, I hope to have my this project done in the next couple of weeks. Will be back to share!