Personal Library issue after update/migrate from legacy

I set-up a library to handle various adjustable flash patterns that worked fine on legacy applications. I’ve migrated the library and verified it even compiles on it’s own but when I add it to my firmware in the Web IDE it fails compile with the error(s) below. How can RGB.control() not be declared? Do I need to include a special dependent library to get this to work now? I published the library by accident as I was learning the Atom Windows IDE (doh).
The name is OB_LED_Flasher_IV

Any help would be appreciated.

//---- Main Blink Control - all colors ----------
void LED_Blinker(int countb, int flashRateOn, int flashRateOff, int brightv){

  RGB.control(true);   // take control of the RGB LED

Error:

In file included from lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.cpp:1:0:
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h: In function ‘void LED_Blinker(int, int, int, int)’:
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:63:3: error: ‘RGB’ was not declared in this scope
RGB.control(true); // take control of the RGB LED
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:73:32: error: ‘delay’ was not declared in this scope
delay(100*flashRateOn); // wait

@MisterNetwork are you compiling using v0.6.1 in Web IDE for the :star: device?

Hi Kenneth!
Thanks for the reply.
Yes V0.6.1 in Web IDE.

Hmm… So you compiled with a local toolchain and it worked fine?

No - what I meant was if I load the library as a stand-alone app it compiles fine on Web IDE, but including same code as a library fails with indicated errors.

Ah ok… Did you add #include "Particle.h" in the header file when you turn it into a library?

Can you also try to compile against v0.6.0 and see if that worked?

Ah - I think I tried it but not sure where it goes. In OB_LED_Flasher_IV.ccp or in OB_LED_Flasher_IV.h?

You will need to add it here

OK Tried that
BTW - just FYI my app main app compiles fine without this library.
Added #include “Particle.h” in first line of OB_LED_Flasher_IV.h
and:

../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: multiple definition of `LED_Blinker(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_reset(int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:86: multiple definition of `LED_Red_Flash(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:86: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_Green_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:98: multiple definition of `LED_Green_Flash(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:98: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_Blue_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:109: multiple definition of `LED_Blue_Flash(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:109: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_Yellow_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:120: multiple definition of `LED_Yellow_Flash(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:120: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_Orange_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:131: multiple definition of `LED_Orange_Flash(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:131: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_Cyan_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:142: multiple definition of `LED_Cyan_Flash(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:142: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_Magenta_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:153: multiple definition of `LED_Magenta_Flash(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:153: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:164: multiple definition of `LED_White_Flash(int, int, int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:164: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_Rainbow_Flash(int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:178: multiple definition of `LED_Rainbow_Flash(int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:178: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_reset(int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:210: multiple definition of `LED_reset(int, int)'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:210: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: multiple definition of `bright1'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):/spark/compile_service/shared/workspace/6_photon_0.6.1_105_4/firmware/user/../wiring/inc/spark_wiring_cloud.h:231: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: multiple definition of `countr2'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):/spark/compile_service/shared/workspace/6_photon_0.6.1_105_4/firmware/user/../wiring/inc/spark_wiring_cloud.h:231: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: multiple definition of `countr'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):/spark/compile_service/shared/workspace/6_photon_0.6.1_105_4/firmware/user/../wiring/inc/spark_wiring_cloud.h:231: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: multiple definition of `count'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):/spark/compile_service/shared/workspace/6_photon_0.6.1_105_4/firmware/user/../wiring/inc/spark_wiring_cloud.h:231: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: multiple definition of `lblue'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):/spark/compile_service/shared/workspace/6_photon_0.6.1_105_4/firmware/user/../wiring/inc/spark_wiring_cloud.h:231: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: multiple definition of `lgreen'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):/spark/compile_service/shared/workspace/6_photon_0.6.1_105_4/firmware/user/../wiring/inc/spark_wiring_cloud.h:231: first defined here
../../../build/target/user/platform-6/libuser.a(OB_LED_Flasher_IV.o): In function `LED_White_Flash(int, int, int, int)':
lib/OB_LED_Flasher_IV/src/OB_LED_Flasher_IV.h:62: multiple definition of `lred'
../../../build/target/user/platform-6/libuser.a(doorpropalert04.o):/spark/compile_service/shared/workspace/6_photon_0.6.1_105_4/firmware/user/../wiring/inc/spark_wiring_cloud.h:231: first defined here
collect2: error: ld returned 1 exit status
make: *** [b0e55400eedcc10541f89bfac63985d192259496937f2ccf847c3b3c1c8e.elf] Error 1

PS - can you recommend a good resource that explains about libraries. When to use file_name.cpp file_name.ino file_name.h and what should be in them, etc. ?

Libraries should not use .ino files (unless for sample projects) and it is not allowed to have an .ino and .cpp file with the same name in a project since the .ino will be turned into a .cpp after the preprocessor treatment.

And when to use .h vs. .cpp is a C/C++ topic that should be googlable :wink:

Your error log above suggests you’ve got the lib imported twice (maybe as imported lib and as file tabs) or you have not protected your header (.h) file against multi-inclusion (via #ifndef or #pragma once)

1 Like

…and when to use #include guards?

here is a good place to start

2 Likes

Bingo! When the library was migrated it put

#include "OB_LED_Flasher_IV.h" 

in OB_LED_Flasher_IV.cpp, and my lack of experience didn’t realize that was redundant.

Thanks for everyone’s help! :slight_smile:

1 Like

Actually you need to have that include in the lib implementation file (.cpp), but you need to guard your header file against multi-inclusion.