Arduino Forum

Using Arduino => Programming Questions => Topic started by: Bugflip on Mar 22, 2019, 06:32 pm

Title: Undefined reference to for a class
Post by: Bugflip on Mar 22, 2019, 06:32 pm
When  I compile my main code, it gives me an error and I read up about it but couldn't find anything.







Code: [Select]
/*
 * The Effect abstract class for the GauntletII project.
 */

#ifndef Effect_h
#define Effect_h

#import <FastLED.h>

class Effect {

    protected:
        CRGB *leds;
        int width, height;
   
        struct CRGB& pixel(int x, int y);
        bool inXRange(int x);
        bool inYRange(int y);
   
        void clearLeds();

    public:
        Effect(CRGB *leds, int width, int height);

        virtual void start() {};

};

#endif



Code: [Select]
Arduino: 1.8.8 (Mac OS X), Board: "Arduino/Genuino Uno"

In file included from sketch/Effect.h:8:0,
                 from sketch/twinkle.cpp:5:
/Users/jonathanfelix/Documents/Arduino/libraries/FastLED/FastLED.h:17:21: note: #pragma message: FastLED version 3.002.000
 #    pragma message "FastLED version 3.002.000"
                     ^
In file included from sketch/Effect.h:8:0,
                 from sketch/twinkle.cpp:5,
                 from /Users/jonathanfelix/Documents/Arduino/sd_card_lights/sd_card_lights.ino:4:
/Users/jonathanfelix/Documents/Arduino/libraries/FastLED/FastLED.h:17:21: note: #pragma message: FastLED version 3.002.000
 #    pragma message "FastLED version 3.002.000"
                     ^
/var/folders/sn/s5gtxzh907q8mmf73yr8fjs40000gn/T//ccEmA6Db.ltrans1.ltrans.o: In function `Twinkle::Twinkle(CRGB*, int, int, bool, bool)':
sketch/twinkle.cpp:27: undefined reference to `Effect::Effect(CRGB*, int, int)'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Title: Re: Undefined reference to for a class
Post by: gfvalvo on Mar 22, 2019, 06:37 pm
You posted incomplete code. Please supply enough so that we can reproduce the same compiler error.
Title: Re: Undefined reference to for a class
Post by: Bugflip on Mar 22, 2019, 08:35 pm
the rest is really messy I need to organize it and get rid of some variables I'm not using.


Code: [Select]
#include "twinkle.cpp"
int crn = 1;
#define HEIGHT 14
#define WIDTH 14
#include <FastLED.h>

#define NUM_LEDS WIDTH * HEIGHT





#include <SPI.h>
#include <SD.h>

#define DATA_PIN 3    // your data arduino pin
#define CHIPSET WS2812B  // your LED chip type
#define CMD_NEW_DATA 1
//#define BAUD_RATE 500000  //if using Glediator via serial
const byte interruptPin = 2;
unsigned char x = 14; // matrix x size
unsigned char y = 14; // matrix y size
volatile int buttoncount = 0;
static unsigned long last_interrupt_time = 0;


#define MAX_TWINKS 25
#define OFFSET 0xB000







File fxdata;
CRGB leds[NUM_LEDS];

void irpt(){
 
  unsigned long interrupt_time = millis();

  // debounce  
  if ((interrupt_time - last_interrupt_time) > 100)
  {  
  if(buttoncount==8){
    buttoncount=0;
  } else {
  buttoncount++;}
  
  Serial.println(buttoncount);
  
  }
  
  last_interrupt_time = interrupt_time;
  
}


void setup()
{
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), irpt, LOW);
  FastLED.addLeds<CHIPSET, DATA_PIN, GRB>(leds, NUM_LEDS); //see doc for different LED strips
//  Serial.begin(BAUD_RATE); // when using Glediator via usb
  Serial.begin(115200);

  for(int y = 0 ; y < NUM_LEDS ; y++)
  {
    leds[y] = CRGB::Black; // set all leds to black during setup
  }
  FastLED.show();

  pinMode(10, OUTPUT); // CS/SS pin as output for SD library to work.
  

  if (!SD.begin(4))
  {
    Serial.println("sdcard initialization failed!");
    return;
  }
  Serial.println("sdcard initialization done.");

  


}
int serialGlediator ()
{while (!Serial.available()) {}
 return Serial.read(); }

void loop(){
//first
  while(buttoncount==0){
  if (buttoncount!=0){fxdata.close(); break;}
  fxdata = SD.open("pl.dat");
  Serial.println("Good");
  if (buttoncount!=0){
    fxdata.close();
            break;
        }
  if (fxdata){
    if (buttoncount!=0){
      fxdata.close();
            break;
        }
      
    }

  while (fxdata.available()){
    if (buttoncount!=0){
      fxdata.close();
            break;
        }
    fxdata.readBytes((char*)leds, NUM_LEDS*3);
    if (buttoncount!=0){
      fxdata.close();
            break;
        }
    ledSort(crn);
    if (buttoncount!=0){
      fxdata.close();
            break;
        }//1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
     FastLED.show();
     if (buttoncount!=0){
      fxdata.close();
            break;
        }
    delay(10);
    if (buttoncount!=0){
      fxdata.close();
            break;
        }// set the speed of the animation. 20 is appx ~ 500k bauds
  }
if (buttoncount!=0){
            fxdata.close();
            break;
            
        }
  
  fxdata.close();
}



//second
while(buttoncount==1){
  if (buttoncount!=1){
    fxdata.close();
            break;}
  fxdata = SD.open("slow.dat");  
  if (buttoncount!=1){
    fxdata.close();
            break;
        }
  if (fxdata){
    if (buttoncount!=1){
      fxdata.close();
            break;
        }
      
    }

  while (fxdata.available()){
    if (buttoncount!=1){
      fxdata.close();
            break;
        }
    fxdata.readBytes((char*)leds, NUM_LEDS*3);
    if (buttoncount!=1){
      fxdata.close();
            break;
        }
    ledSort(crn);
    if (buttoncount!=1){
      fxdata.close();
            break;
        }//1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
     FastLED.show();
     if (buttoncount!=1){
      fxdata.close();
            break;
        }
    delay(10);
    if (buttoncount!=1){
      fxdata.close();
            break;
        }// set the speed of the animation. 20 is appx ~ 500k bauds
  }
if (buttoncount!=1){
            fxdata.close();
            break;
            
        }
  
  fxdata.close();
}


//third

while(buttoncount==2){
  if (buttoncount!=2){
    fxdata.close();
            break;}
  fxdata = SD.open("cplasma.dat");  
  if (buttoncount!=2){
    fxdata.close();
            break;
        }
  if (fxdata){
    if (buttoncount!=2){
      fxdata.close();
            break;
        } }

  while (fxdata.available()){
    if (buttoncount!=2){
      fxdata.close();
            break;
        }
    fxdata.readBytes((char*)leds, NUM_LEDS*3);
    if (buttoncount!=2){
      fxdata.close();
            break;
        }
    ledSort(crn);
    if (buttoncount!=2){
      fxdata.close();
            break;
        }//1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
     FastLED.show();
     if (buttoncount!=2){
      fxdata.close();
            break;
        }
    delay(10);
    if (buttoncount!=2){
      fxdata.close();
            break;
        }// set the speed of the animation. 20 is appx ~ 500k bauds
  }
if (buttoncount!=2){
            fxdata.close();
            break;
            
        }
  
  fxdata.close();
}

//fourth

while(buttoncount==3){
  if (buttoncount!=3){
    fxdata.close();
            break;}
  fxdata = SD.open("fire.dat");  
  if (buttoncount!=3){
    fxdata.close();
            break;
        }
  if (fxdata){
    if (buttoncount!=3){
      fxdata.close();
            break;
        }
      
    }

  while (fxdata.available()){
    if (buttoncount!=3){
      fxdata.close();
            break;
        }
    fxdata.readBytes((char*)leds, NUM_LEDS*3);
    if (buttoncount!=3){
      fxdata.close();
            break;
        }
    ledSort(crn);
    if (buttoncount!=3){
      fxdata.close();
            break;
        }//1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
     FastLED.show();
     if (buttoncount!=3){
      fxdata.close();
            break;
        }
    delay(20);
    if (buttoncount!=3){
      fxdata.close();
            break;
        }// set the speed of the animation. 20 is appx ~ 500k bauds
  }
if (buttoncount!=3){
            fxdata.close();
            break;
            
        }
  
  fxdata.close();
}

 
Heres the first part its too big to post at one time
Title: Re: Undefined reference to for a class
Post by: johnwasser on Mar 22, 2019, 08:42 pm
The Effect.cpp file is not being included in your build (or it doesn't define the object constructor).
Title: Re: Undefined reference to for a class
Post by: gfvalvo on Mar 22, 2019, 08:47 pm
Code: [Select]
#include "twinkle.cpp"
That, in itself is an unusual thing to do.

the rest is really messy I need to organize it and get rid of some variables I'm not using.
Agreed. Better to post an MCVE (https://stackoverflow.com/help/mcve)
Title: Re: Undefined reference to for a class
Post by: Bugflip on Mar 22, 2019, 08:59 pm
and heres the second part

Code: [Select]
//fifth

while(buttoncount==4){
  if (buttoncount!=4){
    fxdata.close();
            break;}
  fxdata = SD.open("frac.dat");  
  if (buttoncount!=4){
    fxdata.close();
            break;
        }
  if (fxdata){
    if (buttoncount!=4){
      fxdata.close();
            break;
        }
      
    }

  while (fxdata.available()){
    if (buttoncount!=4){
      fxdata.close();
            break;
        }
    fxdata.readBytes((char*)leds, NUM_LEDS*3);
    if (buttoncount!=4){
      fxdata.close();
            break;
        }
    ledSort(crn);
    if (buttoncount!=4){
      fxdata.close();
            break;
        }//1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
     FastLED.show();
     if (buttoncount!=4){
      fxdata.close();
            break;
        }
    delay(20);
    if (buttoncount!=4){
      fxdata.close();
            break;
        }// set the speed of the animation. 20 is appx ~ 500k bauds
  }
if (buttoncount!=4){
            fxdata.close();
            break;
            
        }
  
  fxdata.close();
}

//sixth

while(buttoncount==5){
  if (buttoncount!=5){fxdata.close();break;}
  fxdata = SD.open("slow.dat");  
  if (buttoncount!=5){fxdata.close();break;}if (fxdata){
  if (buttoncount!=5){fxdata.close();break;}}

  while (fxdata.available()){
    if (buttoncount!=5){
      fxdata.close();
            break;
        }
    fxdata.readBytes((char*)leds, NUM_LEDS*3);
    if (buttoncount!=5){
      fxdata.close();
            break;
        }
    ledSort(4);
    if (buttoncount!=5){
      fxdata.close();
            break;
        }//1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
     FastLED.show();
     if (buttoncount!=5){
      fxdata.close();
            break;
        }
    delay(10);
    if (buttoncount!=5){
      fxdata.close();
            break;
        }// set the speed of the animation. 20 is appx ~ 500k bauds
  }
if (buttoncount!=5){
            fxdata.close();
            break;
            
        }
  
  fxdata.close();
}

//seventh

while(buttoncount==6){
  if (buttoncount!=6){fxdata.close();break;}
  fxdata = SD.open("sd.dat");  
  if (buttoncount!=6){fxdata.close();break;}if (fxdata){
  if (buttoncount!=6){fxdata.close();break;}}

  while (fxdata.available()){
    if (buttoncount!=6){
      fxdata.close();
            break;
        }
    fxdata.readBytes((char*)leds, NUM_LEDS*3);
    if (buttoncount!=6){
      fxdata.close();
            break;
        }
    ledSort(4);
    if (buttoncount!=6){
      fxdata.close();
            break;
        }//1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
     FastLED.show();
     if (buttoncount!=6){
      fxdata.close();
            break;
        }
    delay(10);
    if (buttoncount!=6){
      fxdata.close();
            break;
        }// set the speed of the animation. 20 is appx ~ 500k bauds
  }
if (buttoncount!=6){
            fxdata.close();
            break;
            
        }
  
  fxdata.close();
}

//eight

while(buttoncount==7){
  if (buttoncount!=7){fxdata.close();break;}
  fxdata = SD.open("lines.dat");  
  if (buttoncount!=7){fxdata.close();break;}if (fxdata){
  if (buttoncount!=7){fxdata.close();break;}}

  while (fxdata.available()){
    if (buttoncount!=7){
      fxdata.close();
            break;
        }
    fxdata.readBytes((char*)leds, NUM_LEDS*3);
    if (buttoncount!=7){
      fxdata.close();
            break;
        }
    ledSort(4);
    if (buttoncount!=7){
      fxdata.close();
            break;
        }//1-4 possible, set your first LED's position. Change the number: 1=TL(top left),2=TR(top right),3=BL(bottom left),4=BR(bottom right)
     FastLED.show();
     if (buttoncount!=7){
      fxdata.close();
            break;
        }
    delay(10);
    if (buttoncount!=7){
      fxdata.close();
            break;
        }// set the speed of the animation. 20 is appx ~ 500k bauds
  }
if (buttoncount!=7){
            fxdata.close();
            break;
            
        }
  
  fxdata.close();
}

while(buttoncount==8){
  doTwinkle();
}












}


void doTwinkle() {
    Twinkle twinkle(leds, WIDTH, HEIGHT, true, true);
    twinkle.start();
}




 
int ledSort (int modus) { //1=TL,2=TR,3=BL,4=BR, this function will rearrange the led array ;-)
    
 CRGB tmp[x];
    if(modus == 3 || modus == 4) {

  for(int i = 0; i < (y / 2);i++) {
      for(int j = 0; j < x;j++) {
    tmp[j] = leds[i * x + j];
    leds[i * x] = leds[(y - i - 1) * x];
    leds[(y - i - 1) * x] = tmp[j];
       }
        }
     }

     if(modus == 1 || modus == 3) {
       for(int i = 1; i < y; i = i + 2) {
       for(int j = x; j > 0;j--) {
        tmp[(x - j)] = leds[i * x + j - 1];
          }
           for(int j = 0; j < x;j++) {
      leds[i * x + j] = tmp[j];
      }
       }

      }


     if(modus == 2 | modus == 4) {
      for(int i = 0; i < y; i = i + 2) {
       for(int j = x; j > 0;j--) {
        tmp[(x - j)] = leds[i * x + j - 1];
          }
           for(int j = 0; j < x;j++) {
      leds[i * x + j] = tmp[j];
      }
       }

      }
      return 1;
}
Title: Re: Undefined reference to for a class
Post by: gfvalvo on Mar 22, 2019, 09:05 pm
Code: [Select]
#import <FastLED.h>
We don't '#import' in C++.
Title: Re: Undefined reference to for a class
Post by: Bugflip on Mar 23, 2019, 12:57 am
Code: [Select]
#include "twinkle.cpp"
That, in itself is an unusual thing to do.
what should I do then?
Title: Re: Undefined reference to for a class
Post by: gfvalvo on Mar 23, 2019, 01:21 am
See My Reply #3 to This Discussion Thread (https://forum.arduino.cc/index.php?topic=588837.msg4005111#msg4005111).