hideakitai / Dynamixel

Arduino library for Dynamixel
MIT License
20 stars 9 forks source link

multiple definition of `void arduino::dynamixel::Dynamixel::addModel...' #5

Closed wynn4 closed 2 years ago

wynn4 commented 2 years ago

In my main.ino file, I include the library using #include "Dynamixel.h" and I create an instance of Dynamixel just like the example in the README. This basic example works just fine. However I can't seem to pass a reference of this Dynamixel instance to a custom class of mine (defined in separate .h and .cpp files) because I get the following error when I add #include "Dynamixel.h" to my custom class .h file:

c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\bits/shared_ptr_base.h:311: multiple definition of `void arduino::dynamixel::Dynamixel::addModel<(arduino::dynamixel::Model)2>(unsigned char)' C:\Users\wynn4\AppData\Local\Temp\1\arduino_build_773536\sketch\teensy_hydrophone_payload.ino.cpp.o:C:\Users\wynn4\Documents\Arduino\libraries\Dynamixel-master/Dynamixel/Dynamixel.h:393: first defined here c:/program files (x86)/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

Any ideas of what is going on here? Googling around and it seems like this kind of issue might be caused by variable definitions being part of the Dynamixel.h file and not strictly variable declarations

I have tried doing similar things with other Libraries (OneWire for example) and I don't have this "multiple definitions" issue.

Thank you.

hideakitai commented 2 years ago

@wynn4 Hi, could you give me your minimum code that can reproduce your problem? Also, please let me know about your environment.

wynn4 commented 2 years ago

@hideakitai thanks for looking into this. Here's my minimum example compiling for the Arduino Uno:

min_example.ino:

#include <Dynamixel.h>
#include "manager.h"
Dynamixel dxl(2);
Manager manager(dxl);
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

manager.h:

#ifndef MANAGER_H
#define MANAGER_H
#include <Dynamixel.h>
class Manager
{
public:
  Manager(Dynamixel& dxl);
private:
  Dynamixel* dxl_;
};
#endif//MANAGER_H

manager.cpp:

#include "manager.h"

Manager::Manager(Dynamixel& dxl)
{
  dxl_ = &dxl;
}

I'm using Arduino IDE version 1.8.16

hideakitai commented 2 years ago

@wynn4 Sorry for the late reply. Fixed in v0.2.1. If you still have a problem, let me know, please.