Particle Flashing CLI - Undefined reference NeoPixel Library

So since I’m getting the infamous building binary failed error I attempted to flash my code using CLI.
This is the result when trying to flash the NeoPixel example. Any idea why I’m getting these undefined reference errors?

C:\Users\s125556\My Documents\Photon Firmware>particle flash 23003b0013473433393
83037 neopixel
Including:
    C:/Users/s125556/My Documents/Photon Firmware/neopixel/neopixel.h
    C:/Users/s125556/My Documents/Photon Firmware/neopixel/neopixel.ino
    C:/Users/s125556/My Documents/Photon Firmware/neopixel/neopixel.cpp
attempting to flash firmware to your device 23003b001347343339383037
Flash device failed
../../../build/target/user/platform-6/libuser.a(neopixel.o): In function `setup'
:
neopixel.cpp:22: undefined reference to `Adafruit_NeoPixel::begin()'
neopixel.cpp:23: undefined reference to `Adafruit_NeoPixel::show()'
../../../build/target/user/platform-6/libuser.a(neopixel.o): In function `Wheel(
unsigned char)':
neopixel.cpp:46: undefined reference to `Adafruit_NeoPixel::Color(unsigned char,
 unsigned char, unsigned char)'
neopixel.cpp:49: undefined reference to `Adafruit_NeoPixel::Color(unsigned char,
 unsigned char, unsigned char)'
neopixel.cpp:52: undefined reference to `Adafruit_NeoPixel::Color(unsigned char,
 unsigned char, unsigned char)'
../../../build/target/user/platform-6/libuser.a(neopixel.o): In function `rainbo
w(unsigned char)':
neopixel.cpp:34: undefined reference to `Adafruit_NeoPixel::numPixels() const'
neopixel.cpp:35: undefined reference to `Adafruit_NeoPixel::setPixelColor(unsign
ed short, unsigned long)'
neopixel.cpp:37: undefined reference to `Adafruit_NeoPixel::show()'
../../../build/target/user/platform-6/libuser.a(neopixel.o): In function `__stat
ic_initialization_and_destruction_0':
neopixel.cpp:18: undefined reference to `Adafruit_NeoPixel::Adafruit_NeoPixel(un
signed short, unsigned char, unsigned char)'
neopixel.cpp:18: undefined reference to `Adafruit_NeoPixel::~Adafruit_NeoPixel()
'
collect2: error: ld returned 1 exit status
make: *** [c420fc473f292df8918365af6616780b75e7fc4fd87bc9a2e1a3a6b67ed8.elf] Err
or 1


C:\Users\s125556\My Documents\Photon Firmware>

Would you ming showing us the code that goes along with that? Seems as though the library isn’t included properly.

/*
 * This is a minimal example, see extra-examples.cpp for a version
 * with more explantory documentation, example routines, how to
 * hook up your pixels and all of the pixel types that are supported.
 *
 */

#include "application.h"
#include "neopixel.h"

SYSTEM_MODE(AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 10
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
void loop()
{
  rainbow(20);
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

That’s my .ino file.

That’s the folder

You should rename neopixel.ino to something else, like neopixeltest.ino. The build will fail if you have two files with the same base name, differing only by having an extension .cpp or .ino. This is because both .cpp and .ino files get compiled into a .o file, so one overwrites the other.

1 Like

Thanks, that fixed it and flashing through the Particle Dev works too now!

1 Like