Undefined reference to 'loop / 'setup

Hey there,
everytime I try to compile my project I get the error:

C:\Users\mmitr\AppData\Local\Temp\ccnxFoPo.ltrans0.ltrans.o: In function main’:

:(.text.startup+0x86): undefined reference to setup’

:(.text.startup+0x8e): undefined reference to loop’

collect2.exe: error: ld returned 1 exit status

What’s your platformio.ini like? What code are you trying to compile?

Sorry, I may misclicked and posted without finished writing my post :smiley:
EDIT: I dont know, why it’s not formatted the right way and why its missing something at the end, although it’s visible in the editing window :frowning:

Code:

//Inside RGB_LED.h

#ifndef _RGB_LED_H_
#define _RGB_LED_H_


class RGBLED{
public:
	
	//LED Pins
	int redPin;
	int greenPin;
	int bluePin;
    int whitePin;

	//RGBB Values
	int redValue;
	int greenValue;
	int blueValue;
    int whiteValue;
  

	//Constructor 
	RGBLED(int rPin,int gPin, int bPin,int wpin);
	
	//Basics
	void writeRGB(int red, int green, int blue, int brightness);

    //BrightnessMapping
    int brightMap(int color, int bright);

	//Single Colors
	void writeRed(int red);
	
	void writeGreen(int green);

	void writeBlue(int blue);

    void writeWhite(int brightness);

	//Off
	void turnOff();

	//Animaions
	void writeRandom(int bright);

  //max RGB Values are 254!!
  void pulse(int red, int green, int blue, int brightness);

};


#endif

//Inside RGB_LED.cpp

#include <Arduino.h>
#include <RGB_LED.h>


	//Constructor 
	RGBLED::RGBLED(int rPin,int gPin, int bPin,int wpin){
      redPin = rPin;
	  greenPin = gPin;
	  bluePin = bPin;
	
    turnOff();
  }
	
	//Basics
	void RGBLED::writeRGB(int red, int green, int blue, int brightness){
       red=brightMap(red,brightness);
       blue=brightMap(blue,brightness);
       green=brightMap(green,brightness);
       writeRed(red);
       writeGreen(green);
       writeBlue(blue);
  }

  //BrightnessMapping
  int RGBLED::brightMap(int color, int bright){
       int mapped;
       mapped=map(color,0,255,0,bright);
       return mapped;
  }

	//Single Colors
	void RGBLED::writeRed(int red){
    analogWrite(redPin,red);
  }
	
	void RGBLED::writeGreen(int green){
    analogWrite(greenPin,green);
  }

	void RGBLED::writeBlue(int blue){
    analogWrite(bluePin,blue);
  }

  void RGBLED::writeWhite(int brightness){
     analogWrite(whitePin, brightness);
  }

	//Off
	void RGBLED::turnOff(){
    writeRed(0);
    writeGreen(0);
    writeBlue(0);
    writeWhite(0);
  }

	//Animaions
	void RGBLED::writeRandom(int bright){
	  int r = random(0,255);
	  int g = random(0,255);
  	int b = random(0,255);

  	writeRGB(r,g,b,bright);
  }

  //max RGB Values are 254!!
  void RGBLED::pulse(int red, int green, int blue, int brightness){
    int i;
    for(i=brightness; i>=0; i--){
      writeRGB(red, green, blue, i);
      delay(20);
    }
    for(i; i<=brightness; i++){
      writeRGB(red, green, blue, i);
      delay(20);
    }
  }

//inside main.cpp

#include <Arduino.h>
#include <RGB_LED.h>


//Initialisiere LED Objekt 
RGBLED LED(6,9,10,11);

void setup() {
  // put your setup code here, to run once:

  pinMode(LED.redPin, OUTPUT);
  pinMode(LED.greenPin, OUTPUT);
  pinMode(LED.bluePin, OUTPUT);
  pinMode(LED.whitePin, OUTPUT);
  
}

void loop() {

  LED.writeRGB(255,0,0,150);
  delay(50);

}

//Inside platformio.ini

[env:uno]
platform = atmelavr
board = uno
framework = arduino

src_filter = -<SourceStorage/>`

Try

src_filter = +<*> -<SourceStorage/>

Thanks for your answer, but now I get different errors according to other functions:

C:\Users\mmitr\AppData\Local\Temp\cc4H7eIO.ltrans0.ltrans.o: In function main’:

:(.text.startup+0xbe): undefined reference to RGBLED::writeRGB(int, int, int, int)’

C:\Users\mmitr\AppData\Local\Temp\cc4H7eIO.ltrans0.ltrans.o: In function _GLOBAL__sub_I_LED’:

:(.text.startup+0x130): undefined reference to RGBLED::RGBLED(int, int, int, int)’
collect2.exe: error: ld returned 1 exit status

And in what folder is RGB_LED.cpp located?

In the include folder, which was automatically created. RGB_LED.h and RGB_LED.cpp are located there.

Sources under include don’t seem to compiled then? (makes sense considering the name…). Move the RGB_LED.cpp to the src/ then.

1 Like

Very big thanks dude. This was the problem, now it compiles and Uploads just fine. Didn’t thought about the fact, that include folder won’t compile :smiley:
I’m just getting started with additional header and source and never tried it before.

This topic can be closed .