Multiple definitions from an Adafruit example

Hi,

I know the meaning of duplicate definitions, but for the life of me, I cannot see where it is coming from. I have literally copied this code from the Adafruit examples, into a brand new sketch, included the two libraries and get the errors:-

C:\Users\david\AppData\Local\arduino\sketches\0F451F22A7BC3D7E442579BC90548809\libraries\Adafruit_Unified_Sensor\Adafruit_Sensor.cpp.o (symbol from plugin): In function Adafruit_Sensor::printSensorDetails()':
(.text+0x0): multiple definition of `Adafruit_Sensor::printSensorDetails()'
C:\Users\david\AppData\Local\arduino\sketches\0F451F22A7BC3D7E442579BC90548809\libraries\Adafruit_Unified_Sensor\Adafruit_Sensor - Copy.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

I'm using a Nano Every. Here is the offending code:

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN 2     // Digital pin connected to the DHT sensor 
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.

// Uncomment the type of sensor in use:
//#define DHTTYPE    DHT11     // DHT 11
//define DHTTYPE    DHT22     // DHT 22 (AM2302)
#define DHTTYPE    DHT21     // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
//   https://learn.adafruit.com/dht/overview

DHT_Unified dht(DHTPIN, DHTTYPE);

uint32_t delayMS;

void setup() {
  Serial.begin(9600);
  // Initialize device.
  dht.begin();
  Serial.println(F("DHTxx Unified Sensor Example"));
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  Serial.println(F("------------------------------------"));
  Serial.println(F("Temperature Sensor"));
  Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
  Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
  Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
  Serial.println(F("------------------------------------"));
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  Serial.println(F("Humidity Sensor"));
  Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("%"));
  Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("%"));
  Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("%"));
  Serial.println(F("------------------------------------"));
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;
}

void loop() {
  // Delay between measurements.
  delay(delayMS);
  // Get temperature event and print its value.
  sensors_event_t event;
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println(F("Error reading temperature!"));
  }
  else {
    Serial.print(F("Temperature: "));
    Serial.print(event.temperature);
    Serial.println(F("°C"));
  }
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    Serial.println(F("Error reading humidity!"));
  }
  else {
    Serial.print(F("Humidity: "));
    Serial.print(event.relative_humidity);
    Serial.println(F("%"));
  }
}

Hi @davej61. You have a redundant copy of the library source file. This is the cause of the "multiple definition" error.

Delete the file at this path on your hard drive:

<sketchbook folder>\libraries\Adafruit_Unified_Sensor\Adafruit_Sensor - Copy.cpp

(where <sketchbook folder> is the path set in Arduino IDE's "Sketchbook location" preference)

After doing that, try compiling again. Hopefully it will now compile successfully.

Hi @ptillisch,
Wow, thanks for that as it did the trick but I have absolutely no idea how the heck it got there. Now I'me getting the age old problem of a lack of serial ports. I've tried various cables. Also now with this error, "Access is denied". I can see that it may be in use but there is nothing else running that would use that port. It's been a while since I messed around with Arduino stuff and to be honest is driving me nuts at the moment.

Sketch uses 8556 bytes (17%) of program storage space. Maximum is 49152 bytes.
Global variables use 227 bytes (3%) of dynamic memory, leaving 5917 bytes for local variables. Maximum is 6144 bytes.
Performing 1200-bps touch reset on serial port COM5
Cannot perform port reset: 1200-bps touch: opening port at 1200bps: Serial port busy
"C:\Users\david\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\david\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega4809 -cjtag2updi -PCOM5  -b115200 -e -D "-Uflash:w:C:\Users\david\AppData\Local\arduino\sketches\0F451F22A7BC3D7E442579BC90548809/TempMonitor.ino.hex:i" "-Ufuse2:w:0x01:m" "-Ufuse5:w:0xC9:m" "-Ufuse8:w:0x00:m" {upload.extra_files}

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\david\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : jtag2updi
         Overriding Baud Rate          : 115200
avrdude: ser_open(): can't open device "\\.\COM5": Access is denied.



avrdude done.  Thank you.

Failed uploading: uploading error: exit status 1

Hi,
Cancel that. I have just rebooted my machine and it is working. No idea what caused that. Microsoft glitch...
Thanks @ptillisch very much for your help

Thanks for taking the time to post an update! I'm glad everything is working now.

Regards, Per