Trouble compiling with Adafruit-MotorShield-V2

I’m trying to get started on an app that will control some simple DC motors with an Argon. It appears the Adafruit DC Motor + Stepper FeatherWing Add-on For All Feather Boards would be a good fit. While I wait for delivery of that board, I thought I’d get started on the application. Unfortunately I’m having an issue with multiple definitions and I’ve tried numerous things to resolve the issue, but without success. I am using Dev (VSC) for development as usual.

Here’s my very simple app:

/*
 * Project witchV1
 * Description:  Halloween witch manequin automation
 * Author: Tom Morrison
 * Date:  April 2021->
 */

#include "application.h"
#include "Adafruit-MotorShield-V2.h"
#include "Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();

Adafruit_DCMotor *head = AFMS.getMotor(1);
Adafruit_DCMotor *mouth = AFMS.getMotor(2);

void setup() {
  AFMS.begin();
  head->setSpeed(100); //0=stopped --> 255=full speed
  mouth->setSpeed(100); //same as above
}

void loop() {
  // Let's just get something moving to test the motor connections and directions.
  head->run(FORWARD);
  delay(1000);
  head->run(BACKWARD);
  head->run(RELEASE);
  //
  mouth->run(FORWARD);
  delay(1000);
  mouth->run(BACKWARD);
  mouth->run(RELEASE);
}

Here’s an example of the errors I continue to get:

:::: COMPILING APPLICATION

Creating /Users/tom/Documents/Particle/Projects-Home/witchV1/target/2.0.1/argon/platform_user_ram.ld ...
/Users/tom/.particle/toolchains/gcc-arm/9.2.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o): in function `Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(unsigned char)':
/Users/tom/.particle/toolchains/deviceOS/2.0.1/user/../wiring/inc/spark_wiring_i2c.h:126: multiple definition of `Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(unsigned char)'; ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o):/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.cpp:23: first defined here
/Users/tom/.particle/toolchains/gcc-arm/9.2.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o): in function `Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(unsigned char)':
/Users/tom/.particle/toolchains/deviceOS/2.0.1/user/../wiring/inc/spark_wiring_i2c.h:126: multiple definition of `Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(unsigned char)'; ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o):/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.cpp:23: first defined here
/Users/tom/.particle/toolchains/gcc-arm/9.2.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o): in function `Adafruit_PWMServoDriver::setPWM(unsigned char, unsigned short, unsigned short)':
/Users/tom/.particle/toolchains/deviceOS/2.0.1/user/../wiring/inc/spark_wiring_i2c.h:126: multiple definition of `Adafruit_PWMServoDriver::setPWM(unsigned char, unsigned short, unsigned short)'; ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o):/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.cpp:59: first defined here
/Users/tom/.particle/toolchains/gcc-arm/9.2.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o): in function `Adafruit_PWMServoDriver::read8(unsigned char)':
/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit_PWMServoDriver/src/Adafruit_PWMServoDriver.cpp:127: multiple definition of `Adafruit_PWMServoDriver::read8(unsigned char)'; ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o):/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.cpp:73: first defined here
/Users/tom/.particle/toolchains/gcc-arm/9.2.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o): in function `Adafruit_PWMServoDriver::write8(unsigned char, unsigned char)':
/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit_PWMServoDriver/src/Adafruit_PWMServoDriver.cpp:136: multiple definition of `Adafruit_PWMServoDriver::write8(unsigned char, unsigned char)'; ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o):/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.cpp:85: first defined here
/Users/tom/.particle/toolchains/gcc-arm/9.2.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o): in function `Adafruit_PWMServoDriver::reset()':
/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit_PWMServoDriver/src/Adafruit_PWMServoDriver.cpp:50: multiple definition of `Adafruit_PWMServoDriver::reset()'; ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o):/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.cpp:33: first defined here
/Users/tom/.particle/toolchains/gcc-arm/9.2.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o): in function `Adafruit_PWMServoDriver::begin()':
/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit_PWMServoDriver/src/Adafruit_PWMServoDriver.cpp:43: multiple definition of `Adafruit_PWMServoDriver::begin()'; ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o):/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.cpp:26: first defined here
/Users/tom/.particle/toolchains/gcc-arm/9.2.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o): in function `Adafruit_PWMServoDriver::setPWMFreq(float)':
/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit_PWMServoDriver/src/Adafruit_PWMServoDriver.cpp:53: multiple definition of `Adafruit_PWMServoDriver::setPWMFreq(float)'; ../../../build/target/user/platform-12-m/witchV1//libuser.a(Adafruit_PWMServoDriver.o):/Users/tom/Documents/Particle/Projects-Home/witchV1/lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.cpp:36: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [/Users/tom/Documents/Particle/Projects-Home/witchV1/target/2.0.1/argon/witchV1.elf] Error 1
make[1]: *** [modules/argon/user-part] Error 2
make: *** [compile-user] Error 2
The terminal process "/bin/bash '-c', 'make -f '/Users/tom/.particle/toolchains/buildscripts/1.10.0/Makefile' compile-user -s'" terminated with exit code: 2.

Press any key to close the terminal.

I even tried compiling via Build, but with the same duplicate errors. I did notice the Adafruit-MotorShield-V2 library includes the Adafruit_PWMServoDriver.h and .cpp files. I tried removing those. I also tried not including those in the app itself, assuming the motor lib included them. I’m perplexed and perhaps too tired and “can’t see the forest for the trees”.

Any suggestions would be greatly appreciated. I’ve just never run across this in the past.

TL;DR: If you clean the project and try building again the errors should go away.


I replicated your project with neopo:

$ neopo create tom argon 2.0.1
$ cd tom
$ vim src/tom.cpp

Added the libraries:

$ particle library add Adafruit-MotorShield
$ particle library add Adafruit_PWMServoDriver
$ neopo libs

And then built the project, getting the same errors:

$ neopo build

I then deleted the Adafruit_PWMServoDriver files from Adafruit-MotorShield-V2:

$ rm lib/Adafruit-MotorShield-V2/src/Adafruit_PWMServoDriver.*

And then cleaned the project:

$ neopo clean

Builds after cleaning were successful:

$ neopo build

:::: COMPILING APPLICATION

Creating /home/nrobinson/code/particle/tom/target/argon/platform_user_ram.ld ...
Creating /home/nrobinson/code/particle/tom/target/argon/platform_user_ram.ld ...
   text	   data	    bss	    dec	    hex	filename
   8520	    108	    540	   9168	   23d0	/home/nrobinson/code/particle/tom/target/argon/tom.elf

*** COMPILED SUCCESSFULLY ***

@nrobinson2000, that worked! The step I missed was “clean the project” after removing the library files. I’ve seen the Particle: Clean application & DeviceOS (local) command in Dev, but don’t really understand its purpose. Thanks for your assistance!

This is just a fun project that will please my wife, as the animated witch’s control board failed for some reason and it gives me an excuse to play with some motors and a sound wings to make her uniquely “ours”.

I hope someone will “fix” the library for the next person who needs to use it.

1 Like