Undefined Reference to function error

Hey guys i have a problem again ... :confused:

Arduino: 1.6.5 (Windows 8.1), Platine: "Arduino/Genuino Uno"

C:\Users\Paul\AppData\Local\Temp\build3280561619484866464.tmp\flyController.cpp.o: In function Gyro::Gyro()': C:\Users\Paul\AppData\Local\Temp\build3280561619484866464.tmp/Gyro.h:14: undefined reference to MPU6050me::MPU6050me()'
C:\Users\Paul\AppData\Local\Temp\build3280561619484866464.tmp\Gyro.cpp.o: In function Gyro::GetVals()': C:\Users\Paul\AppData\Local\Temp\build3280561619484866464.tmp/Gyro.cpp:85: undefined reference to MPU6050me::getIntStatus()'
C:\Users\Paul\AppData\Local\Temp\build3280561619484866464.tmp/Gyro.cpp:87: undefined reference to MPU6050me::getFIFOCount()' C:\Users\Paul\AppData\Local\Temp\build3280561619484866464.tmp/Gyro.cpp:90: undefined reference to MPU6050me::resetFIFO()'
C:\Users\Paul\AppData\Local\Temp\build3280561619484866464.tmp/Gyro.cpp:96: undefined reference to MPU6050me::getFIFOBytes(unsigned char*, unsigned char)' C:\Users\Paul\AppData\Local\Temp\build3280561619484866464.tmp/Gyro.cpp:95: undefined reference to MPU6050me::getFIFOCount()'
collect2.exe: error: ld returned 1 exit status
Fehler beim Kompilieren.

I cant find my fault and when i'm googleing i just find that someone missed the class:: in front of the function or that they compiled in command with g++ and had written the wrong command...:confused:

Mpu5060me.h MPU5060me.h - Pastebin.com
Mpu5060me.cpp MPU5060cppcpp - Pastebin.com
Gyro.cpp Gyro.cpp - Pastebin.com

btw its not my code i just tried to modify it that it works for me/ fitted my needs...

MFG paul

I do not bother to load all that scattered pastebin stuff.

Maybe this can give you some hints:

Hi,
We cannot give you any solutions if we do not have your sketch t look for the problems.

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom.... :slight_smile:

Hey Guys,

sure :slight_smile: i just couldn't post the other source in code format because it's too long :confused:

/*
 Name:		JustFLY.ino
 Created:	03.10.2015 16:36:45
 Author:	Paul
*/

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#endif

#include "ypr.h"
#include "Servo.h"
#include "Motor.h"
#include "Gyro.h"
#include "Wire.h"
#include "I2Cdev.h"
#include "helper_3dmath.h"
#include "MPU6050me.h"
#include "flyController.h"
#include "QuadCop.h"

QuadCop quad;

void setup() {
	quad = *new QuadCop(0,1,2,3);
	quad.setYPR(0, 0, 0);
}

// the loop function runs over and over again until power down or reset
void loop() {
	quad.Stableize();
}

Quadcop.h

// QuadCop.h


#ifndef _QUADCOP_h
#define _QUADCOP_h
#if defined(ARDUINO) && ARDUINO >= 100
	#include "arduino.h"
	#include "ypr.h"
	#include "flyController.h"
	
#else
	#include "WProgram.h"
#endif

class QuadCop{
private:
	FlyController flyCon;

public:
	QuadCop(int motorPin1, int motorPin2, int motorPin3, int motorPin4);
	QuadCop();
	void setYPR(float Yaw,float Pitch, float Roll);
	void setYPR(YPR ypr);
	void Stableize();
};

#endif

QuadCop.cpp

#include "QuadCop.h"

QuadCop::QuadCop(int motorPin1, int motorPin2, int motorPin3,int motorPin4){
	flyCon = *new FlyController(motorPin1, motorPin2, motorPin3, motorPin4);
}

void QuadCop::setYPR(float Yaw, float Pitch, float Roll)
{
	flyCon.setWantedYPR(*new YPR(Yaw, Pitch, Roll));
}
void QuadCop::setYPR(YPR ypr)
{
	flyCon.setWantedYPR(ypr);
}
QuadCop::QuadCop(){

}

void QuadCop::Stableize(){
	flyCon.Refresh();
}
// Gyro.h

#ifndef _GYRO_h
#define _GYRO_h

#if defined(ARDUINO) && ARDUINO >= 100

#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050me.h"
#include "ypr.h"
#endif

class Gyro{


private:
	MPU6050me mpu;
#define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6)
	bool blinkState;
	// MPU control/status vars
	bool dmpReady = false;  // set true if DMP init was successful
	uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
	uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
	uint16_t fifoCount;     // count of all bytes currently in FIFO
	uint8_t fifoBuffer[64]; // FIFO storage buffer
	uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
	// orientation/motion vars
	Quaternion q;           // [w, x, y, z]         quaternion container
	VectorInt16 aa;         // [x, y, z]            accel sensor measurements
	VectorInt16 aaReal;     // [x, y, z]            gravity-free accel sensor measurements
	VectorInt16 aaWorld;    // [x, y, z]            world-frame accel sensor measurements
	VectorFloat gravity;    // [x, y, z]            gravity vector
	float euler[3];         // [psi, theta, phi]    Euler angle container
	float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector

	// packet structure for InvenSense teapot demo
	uint8_t teapotPacket[14] = { '

Gyro.cpp

#include "Gyro.h"
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
//#include"Wire.h"
#endif


volatile bool Gyro::mpuInterrupt = false;
YPR lastRedYPR;

void dmpDataReady() {
	Gyro::setMpuIntStatus(true);
}

static void setMpuIntStatus(volatile bool status)
{
	Gyro::mpuInterrupt = status;
}

void Gyro::init() {
	mpu = *new MPU6050me();
	lastRedYPR = *new YPR();
	// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
	Wire.begin();
	TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
	Fastwire::setup(400, true);
#endif

	Serial.begin(115200);
	while (!Serial); // wait for Leonardo enumeration, others continue immediately
	Serial.println(F("Initializing I2C devices..."));
	mpu.initialize();

	// verify connection
	Serial.println(F("Testing device connections..."));
	Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

	// wait for ready
	Serial.println(F("\nSend any character to begin DMP programming and demo: "));
	while (Serial.available() && Serial.read());
	while (!Serial.available());
	while (Serial.available() && Serial.read());

	// load and configure the DMP
	Serial.println(F("Initializing DMP..."));
	devStatus = mpu.dmpInitialize();

	mpu.setXGyroOffset(220);
	mpu.setYGyroOffset(76);
	mpu.setZGyroOffset(-85);
	mpu.setZAccelOffset(1788);

	if (devStatus == 0) {
		// turn on the DMP, now that it's ready
		Serial.println(F("Enabling DMP..."));
		mpu.setDMPEnabled(true);

		// enable Arduino interrupt detection
		Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
		attachInterrupt(0, dmpDataReady, RISING);
		mpuIntStatus = mpu.getIntStatus();

		// set our DMP Ready flag so the main loop() function knows it's okay to use it
		Serial.println(F("DMP ready! Waiting for first interrupt..."));
		dmpReady = true;

		packetSize = mpu.dmpGetFIFOPacketSize();
	}
	else {

		Serial.print(F("DMP Initialization failed (code "));
		Serial.print(devStatus);
		Serial.println(F(")"));
	}

	pinMode(LED_PIN, OUTPUT);
}

YPR Gyro::GetVals() {
	if (!dmpReady) return *new YPR(-1, -1, -1);
	while (!mpuInterrupt && fifoCount < packetSize) {
	}
	mpuInterrupt = false;
	mpuIntStatus = mpu.getIntStatus();

	fifoCount = mpu.getFIFOCount();

	if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
		mpu.resetFIFO();
		Serial.println(F("FIFO overflow!"));
		return *new YPR(-1,-1,-1);
	}
	else if (mpuIntStatus & 0x02) {
		while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
		mpu.getFIFOBytes(fifoBuffer, packetSize);

		fifoCount -= packetSize;
		lastRedYPR.setNewVals(ypr[0] * 180 / M_PI, ypr[1] * 180 / M_PI, ypr[2] * 180 / M_PI);
		return lastRedYPR;
}
}

I posted a few code pieces more that you can understand the problem...

Thanks alot for help :slight_smile:

, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x00, '\r', '\n' };

public:
volatile static bool mpuInterrupt; // indicates whether MPU interrupt pin has gone high
void static setMpuIntStatus(uint8_t status);
void init();
YPR GetVals();
};

#endif


Gyro.cpp

§DISCOURSE_HOISTED_CODE_4§


I posted a few code pieces more that you can understand the problem...

Thanks alot for help :)

Whandall:
I do not bother to load all that scattered pastebin stuff.

Maybe this can give you some hints:
Classes within Classes - Initialiser Lists

Thanks but i think it's not targeting my Problem...

I tried to regenerate your error here, but due to missing librarys gave up after some rounds of installing.

Your object contains subobjects, the linker complains about a nonexistent constructor,
so I still believe that the provided link is very much targeting your problem.

Your methode for object initialization seems very uncommon (at least to me)

QuadCop quad;

	quad = *new QuadCop(0,1,2,3);

compared to a 'standard'

QuadCop *quad;

	quad = new QuadCop(0,1,2,3);

the latter not needing a copy operation.

Whandall:
I tried to regenerate your error here, but due to missing librarys gave up after some rounds of installing.

Your object contains subobjects, the linker complains about a nonexistent constructor,
so I still believe that the provided link is very much targeting your problem.

Your methode for object initialization seems very uncommon (at least to me)

QuadCop quad;
quad = *new QuadCop(0,1,2,3);

compared to a 'standard'

QuadCop *quad;

quad = new QuadCop(0,1,2,3);

the latter not needing a copy operation.

Hey there ....

Sry it seems that I'm in idiot... I Red the Post now the 6th time and if i understood it right i just have to copy in this into GYro.cpp dont i ? :confused:

Gyro::Gyro() : mpu()
{

}

if so it doesn't work ....

Okay thanks i changed my *new stuff :slight_smile:

Doesn't anyone know a solution ? :frowning: