unexpected compilation error message

Dear all,

I try to use a 23LC1024 RAM with a software SPI (using the DigitalIO library).

I have modified the SpiRAM library :

header :

#define SOFTSPIRAM_LIB_VERSION "0.1.4"
//    FILE: SoftSpiRAM.h
//  AUTHOR: K. Tyler
// VERSION: 0.1.4
// PURPOSE: Arduino library for the 23A1024/23LC1024 SRAM memory chip 
//     URL: 
//
// HISTORY:
// see SoftSpiRAM.cpp file

#ifndef SoftSpiRAM_h
#define SoftSpiRAM_h

// support for old IDE's
#if ARDUINO < 100
  #include <WProgram.h>
#else
  #include <Arduino.h>
#endif

// #include <SPI.h>
#include "DigitalIO.h"
const uint8_t SOFT_SPI_MISO_PIN =  7;
const uint8_t SOFT_SPI_MOSI_PIN =  8;
const uint8_t SOFT_SPI_SCK_PIN  =  9;
const uint8_t SOFT_SPI_MODE = 0;
SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SOFT_SPI_MODE> mySoftSPI;

// SRAM Instructions
#define RDMR  5
#define WRMR  1
#define WRITE 2
#define READ  3

// SRAM modes
#define BYTE_MODE       0x00
#define PAGE_MODE       0x80
#define SEQUENTIAL_MODE 0x40

class SoftSpiRAM {
  public:
    // Initialize and specify the SS pin
    SoftSpiRAM      (byte ss_Pin);
    
    // Change SS pin (used in multi SRAM chip)
    byte changeSS   (byte ss_Pin);
    
    // Read a single byte from address
    byte readByte   (uint32_t address);
    
    // Write a single byte to address
    void writeByte  (uint32_t address, byte data_byte);
    
    // Read several bytes starting at address and of length into a char buffer
    void readBuffer (uint32_t address, char *buffer, uint32_t length);
    
    // Write several bytes starting at address and of length from a char buffer
    void writeBuffer(uint32_t address, char *buffer, uint32_t length);
    
    // Write several bytes of value, starting at address and of length
    void fillBytes  (uint32_t address, byte value, uint32_t length);
    
  private:
    byte _ss_Pin;
    void setAddressMode(uint32_t address, byte mode);
};

#endif
// END OF FILE

.cpp file :

// FILE: SpiRAM.cpp
// AUTHOR: K. Tyler
// VERSION: 0.1.4
// PURPOSE: Arduino library for the 23A1024/23LC1024 SRAM memory chip
//
// HISTORY:
// 0.1.00 - 2013-12-15  Initial version.
// 0.1.01 - 2013-12-15  Refactored by Rob Tillaart.
// 0.1.02 - 2013-12-17  Changed readBytes & writeBytes name to readBuffer & writeBuffer respectfully.
//                      Added SPI_CLOCK_DIV8 to improve readBuffer reliability.
// 0.1.03 - 2013-12-20  Removed SPI_CLOCK_DIV8 added in version 0.1.02 as user needs to decide if clock needs decreasing.
//                      Added code in SpiRAM to setup SS pin as output for use of non standard SS pins.
// 0.1.4  - 2013-12-28  Changed readBuffer, writeBuffer & fillBytes length from uint16_t to uint32_t.
//                      Added changeSS function to allow multiple SRAM chips.
//
// Released to the public domain
//

#include <SoftSpiRAM.h>

SoftSpiRAM::SoftSpiRAM(byte ss_Pin){
  _ss_Pin = ss_Pin;                     // Store Slave Select pin
  digitalWrite(_ss_Pin,HIGH);           // Set SS pin high
  pinMode(_ss_Pin,OUTPUT);              // Set it to output
  mySoftSPI.begin();                    // Start SPI
}

byte SoftSpiRAM::changeSS(byte ss_Pin){
  byte temp = _ss_Pin;                  // Get current SS pin
  _ss_Pin = ss_Pin;                     // Store Slave Select pin
  digitalWrite(_ss_Pin,HIGH);           // Set SS pin high
  pinMode(_ss_Pin,OUTPUT);              // Set it to output
  return temp;                          // Return previous SS pin
}

byte SoftSpiRAM::readByte(uint32_t address) {
  byte data_byte;
  readBuffer(address, (char*) &data_byte, 1);
  return data_byte;
}

void SoftSpiRAM::writeByte(uint32_t address, byte data_byte) {
  writeBuffer(address, (char*) &data_byte, 1);
}

void SoftSpiRAM::readBuffer(uint32_t address, char *buffer, uint32_t length) {
  digitalWrite(_ss_Pin, LOW);
  setAddressMode(address, READ);
  for (uint32_t i = 0; i < length; i++) buffer[i] = mySoftSPI.transfer(0x00);
  digitalWrite(_ss_Pin, HIGH);
}

void SoftSpiRAM::writeBuffer(uint32_t address, char *buffer, uint32_t length) {
  digitalWrite(_ss_Pin, LOW);
  setAddressMode(address, WRITE);
  for (uint32_t i = 0; i < length; i++) mySoftSPI.transfer(buffer[i]);
  digitalWrite(_ss_Pin, HIGH);
}

void SoftSpiRAM::fillBytes(uint32_t address, byte value, uint32_t length) {
  digitalWrite(_ss_Pin, LOW);
  setAddressMode(address, WRITE);
  for (uint32_t i = 0; i < length; i++) mySoftSPI.transfer(value);
  digitalWrite(_ss_Pin, HIGH);
}

void SoftSpiRAM::setAddressMode(uint32_t address, byte mode) {
  mySoftSPI.transfer(mode);
  mySoftSPI.transfer((byte)(address >> 16));
  mySoftSPI.transfer((byte)(address >> 8));
  mySoftSPI.transfer((byte)address);
}
// END OF FILE

When compiling this test file

#include <SoftSpiRAM.h>

const uint8_t SRAM1_PIN         = 10;

SoftSpiRAM SpiRam(SRAM1_PIN);

unsigned long address = 0x0;
byte data = 0, readData;

//------------------------------------------------------------------------------

void setup() {
  Serial.begin(115200);
}

//------------------------------------------------------------------------------

void loop() {
  SpiRam.writeByte(address, data);
  readData = SpiRam.readByte(address);

  Serial.print("reading at 0x"); Serial.print(address, HEX);
  Serial.print(": 0x"); Serial.println(readData, HEX);

  delay(500);

  data = data + 1 % 0x100 ; address = (address + 1) % 0x20000 ;
}

I have the following error message :

C:\Users\UTILIS~1\AppData\Local\Temp\arduino_build_915073\libraries\SoftSpiRAM\SoftSpiRAM.cpp.o (symbol from plugin): In function `SoftSpiRAM::changeSS(unsigned char)’:

(.text+0x0): multiple definition of `mySoftSPI’

C:\Users\UTILIS~1\AppData\Local\Temp\arduino_build_915073\sketch\OurTestSoftSPI_20170603.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

Utilisation de la bibliothèque SoftSpiRAM prise dans le dossier : C:\Program Files (x86)\arduino-1.8.2\libraries\SoftSpiRAM (legacy)
Utilisation de la bibliothèque DigitalIO-master version 1.0.0 dans le dossier: C:\Program Files (x86)\arduino-1.8.2\libraries\DigitalIO-master
exit status 1
Erreur de compilation pour la carte Arduino Nano

I really don’t understand: mySoftSPI is not used in SoftSpiRAM::changeSS(unsigned char) !!!
Any advice ?

Thanks a lot for your help,
kindest regards,

SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SOFT_SPI_MODE> mySoftSPI;

The definition of mySoftSPI must be in the source and not the header file. Otherwise it gets included in your sketch and also in the code compiled for your library, that’s why the linker sees it twice.