0

As many of you know (if you read my bio or simply read my previous questions), I'm trying to build a rocket. The code was going well, but once I split my objects into 2 files, a .h and .cpp file, this error message appeared.

The full code is on GitHub because it is simply too long!

Here is the error message :

Arduino: 1.8.1 (Windows 7), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpInitialize()'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpPacketAvailable()'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetAccel(long*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetAccel(int*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetAccel(VectorInt16*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetQuaternion(long*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetQuaternion(int*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetQuaternion(Quaternion*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetGyro(long*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetGyro(int*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetGyro(VectorInt16*, unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetLinearAccel(VectorInt16*, VectorInt16*, VectorFloat*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetLinearAccelInWorld(VectorInt16*, VectorInt16*, Quaternion*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetGravity(VectorFloat*, Quaternion*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetEuler(float*, Quaternion*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetYawPitchRoll(float*, Quaternion*, VectorFloat*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpProcessFIFOPacket(unsigned char const*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpReadAndProcessFIFOPacket(unsigned char, unsigned char*)'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

sketch\vehicle.ino.cpp.o (symbol from plugin): In function `Fins':

(.text+0x0): multiple definition of `MPU6050::dmpGetFIFOPacketSize()'

sketch\Gyroscope.cpp.o (symbol from plugin):(.text+0x0): first defined here

exit status 1
Error compiling for board Arduino Pro or Pro Mini.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
1
  • Perhaps edit your question and say whether IDE starts the compile and link, or if not, show the commands used to compile and link the code. Also, while code may be lengthy, in the question you could show a summary of the #include statements used in each unit of code. Feb 1 '17 at 4:02
2

The problem is the way the author of the MPU6050 library wrote MPU6050_6Axis_MotionApps20.h is not compatible with the way you're using the library. Multiple proposals for fixing the issue have been submitted but they are all outdated to some extent:

https://github.com/jrowberg/i2cdevlib/pull/174

download at https://github.com/martinjos/i2cdevlib/archive/master.zip

https://github.com/jrowberg/i2cdevlib/pull/162

download at https://github.com/cgel/i2cdevlib/archive/master.zip

https://github.com/jrowberg/i2cdevlib/pull/268

download at https://github.com/onliner10/i2cdevlib/archive/master.zip

3

This is 3 years way too late, but here's what I did

  1. In my own mpu_sensor.h file, I only included
#ifndef MPU_SENSOR_H
#define MPU_SENSOR_H

#include "MPU6050.h"
#include "helper_3dmath.h"
....
#endif

Note that I don't include MPU6050_6Axis_MotionApps20, since most datatypes are declared in MPU6050 and helper_3dmath

  1. In my mpu_sensor.cpp file, here's my includes:
#include "MPU6050_6Axis_MotionApps20.h"
#include "mpu_sensor.h"

Please note that MPU6050_6Axis_MotionApps20.h must be before the line that includes mpu_sensor.h.

It works now. I agree that the library itself should be updated, but it seems like the author is not updating for the past few years.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.