exit status 1 - expected constructor, destructor, or type conversion before ';'

I am writing this program for an Arduino Uno

I get the following error message:

exit status 1
expected constructor, destructor, or type conversion before ';' token

Although this seems to be a common message and I have read other threads dealing with the same topic, I have not been able to determine what I have done wrong.

My understanding is that the issue with the libraries is not something i need to pursue since the compiler has selected the correct libraries.


I am posting the error output below as well as the code. I appreciate any help I can get on this.

Error Messages

Arduino: 1.8.10 (Mac OS X), Board: "Arduino/Genuino Uno"

dataLogger-002:208:11: error: expected constructor, destructor, or type conversion before ';' token
 logData()
           ^
/Users/pedro/Documents/Arduino/12-01-2019 Data Logger for Calibration Sketch /dataLogger-002/dataLogger-002.ino:208:9: warning: ISO C++ forbids declaration of 'logData' with no type [-fpermissive]
 logData()
         ^
/Users/pedro/Documents/Arduino/12-01-2019 Data Logger for Calibration Sketch /dataLogger-002/dataLogger-002.ino: In function 'int logData()':
dataLogger-002:208:1: error: ambiguating new declaration of 'int logData()'
 logData()
 ^~~~~~~
/Users/pedro/Documents/Arduino/12-01-2019 Data Logger for Calibration Sketch /dataLogger-002/dataLogger-002.ino:82:6: note: old declaration 'void logData()'
 void logData()
      ^~~~~~~
Multiple libraries were found for "Adafruit_BME280.h"
 Used: /Users/pedro/Documents/Arduino/libraries/Adafruit_BME280_Library
Multiple libraries were found for "SPI.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI
Multiple libraries were found for "Wire.h"
 Used: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/Wire
Multiple libraries were found for "SdFatConfig.h"
 Used: /Users/pedro/Documents/Arduino/libraries/SdFat-master
Multiple libraries were found for "Adafruit_Sensor.h"
 Used: /Users/pedro/Documents/Arduino/libraries/Adafruit_Unified_Sensor
[b]exit status 1
expected constructor, destructor, or type conversion before ';' token[/b]

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This is the code. The error seems to apply to the last function in the program.logData()
```
**#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <SPI.h>
#include <SdFatConfig.h>
#include <sdios.h>
#include <FreeStack.h>
#include <MinimumSerial.h>
#include <SdFat.h>
#include <BlockDriver.h>
#include <SysCall.h>

/*
  Libraries for data logger.
/
// #include <SPI.h> Used Include Library Above
// #include "SdFat.h" Used Include Library Above
/

  Libraries for BME280 Sensors
*/
#include <Wire.h>
// #include <Adafruit_Sensor.h> Used Include Library Above
// #include <Adafruit_BME280.h> Used Include Library Above

/*
  TODO - Need to add RTC Libraries
*/

//Setup Sensors as I2C
Adafruit_BME280 bme1; // I2C to Vcc (0x77)
Adafruit_BME280 bme2; // I2C to Gnd (0x76)

unsigned long delayTime; //came from BME_280_2Sensors_Read_SDWrite

// SD chip select pin.  Be sure to disable any other SPI devices such as Enet.
const uint8_t chipSelect = SS;

// Interval between data records in milliseconds.
// The interval must be greater than the maximum SD write latency plus the
// time to acquire and write data to the SD to avoid overrun errors.
// Run the bench example to check the quality of your SD card.
const uint32_t SAMPLE_INTERVAL_MS = 1000;

// Log file base name.  Must be six characters or less.
#define FILE_BASE_NAME "Data"
//------------------------------------------------------------------------------
// File system object.
SdFat sd;

// Log file.
SdFile file;

// Time in micros for next data record.
uint32_t logTime;

//==============================================================================
// User functions.  Edit writeHeader() and logData() for your requirements.

const uint8_t ANALOG_COUNT = 4;

//------------------------------------------------------------------------------
// Write data header.

void writeHeader()
{
  file.print(F("micros"));
  file.print(F(",Temp1"));
  file.print(F(",H1"));
  file.print(F(",Temp2"));
  file.print(F(",H2"));

//  for (uint8_t i = 0; i < ANALOG_COUNT; i++)
  //  {
  //    file.print(F(",adc"));
  //    file.print(i, DEC);
  //  }
  //  file.println();
}

//------------------------------------------------------------------------------
// Log a data record.

void logData()
{
  uint16_t data[ANALOG_COUNT];

// Read all channels to avoid SD write latency between readings.
  for (uint8_t i = 0; i < ANALOG_COUNT; i++)
  {
    data[i] = analogRead(i);
  }
  // Write data to file.  Start with log time in micros.
  file.print(logTime);

// Write data to CSV record.
  for (uint8_t i = 0; i < ANALOG_COUNT; i++)
  {
    file.write(',');
    file.print(data[i]);
  }
  file.println();
}
//==============================================================================
// Error messages stored in flash.
#define error(msg) sd.errorHalt(F(msg))
//------------------------------------------------------------------------------
void setup()
{
  const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
  char fileName[13] = FILE_BASE_NAME "00.csv";

Serial.begin(9600);

// Wait for USB Serial
  while (!Serial)
  {
    SysCall::yield();

bool  status;

}

delay(1000);

Serial.println(F("Type any character to start")); //testing without F

while (!Serial.available())
  {
    SysCall::yield();
  }

// Initialize at the highest speed supported by the board that is
  // not over 50 MHz. Try a lower speed if SPI errors occur.
  if (!sd.begin(chipSelect, SD_SCK_MHZ(50)))
  {
    sd.initErrorHalt();
  }

// Find an unused file name.
  if (BASE_NAME_SIZE > 6)
  {
    error("FILE_BASE_NAME too long");
  }

while (sd.exists(fileName))
  {
    if (fileName[BASE_NAME_SIZE + 1] != '9')
    {
      fileName[BASE_NAME_SIZE + 1]++;
    }

else if (fileName[BASE_NAME_SIZE] != '9')
    {
      fileName[BASE_NAME_SIZE + 1] = '0';
      fileName[BASE_NAME_SIZE]++;
    }

else
    {
      error("Can't create file name");
    }
  }
  if (!file.open(fileName, O_WRONLY | O_CREAT | O_EXCL))

{
    error("file.open");
  }

// Read any Serial data.
  do
  {
    delay(10);
  }

while (Serial.available() && Serial.read() >= 0);

Serial.print(F("Logging to: "));
  Serial.println(fileName);
  Serial.println(F("Type any character to stop"));

// Write data header.
  writeHeader();

// Start on a multiple of the sample interval.
  logTime = micros() / (1000UL * SAMPLE_INTERVAL_MS) + 1;
  logTime *= 1000UL * SAMPLE_INTERVAL_MS;
}
//------------------------------------------------------------------------------
void loop()
{
  // Time for next record.
  logTime += 1000UL * SAMPLE_INTERVAL_MS;

// Wait for log time.
  int32_t diff;
  do
  {
    diff = micros() - logTime;
  } while (diff < 0);

// Check for data rate too high.
  if (diff > 10)
  {
    error("Missed data record");
  }

}

logData()
{
  // Force data to SD and update the directory entry to avoid data loss.
  if (!file.sync() || file.getWriteError())
  {
    error("write error");
  }

if (Serial.available());
  {
    // Close file and stop.
    file.close();
    Serial.println(F("Done"));
    SysCall::halt();
  }
}**
```

// Log a data record.

void logData()
{
  uint16_t data[ANALOG_COUNT];
etc, etc

You have a function named logData

So what is this all about ?

logData()
{
  // Force data to SD and update the directory entry to avoid data loss.
  if (!file.sync() || file.getWriteError())
etc, etc

UKHeliBob:

// Log a data record.

void logData()
{
  uint16_t data[ANALOG_COUNT];
etc, etc



You have a function named logData

So what is this all about ?


logData()
{
  // Force data to SD and update the directory entry to avoid data loss.
  if (!file.sync() || file.getWriteError())
etc, etc

The second logData() is intended to close the SD card file that the data is being logged into. From your question I'm thinking that this needs a different name like closeLogFile.

From your question I'm thinking that this needs a different name like closeLogFile.

You cannot have 2 functions with the same name in the same scope (not strictly true but not in this case), but that is not all that's wrong with it as it has no return type

UKHeliBob:
You cannot have 2 functions with the same name in the same scope (not strictly true but not in this case), but that is not all that's wrong with it as it has no return type

thank you for your help. After your initial comment I changed the name to create a different function and that fixed the issue with the first error.

I am now researching your second comment to figure out how to handle return type correctly. I will let you know of my result.

thanks again.