Go Down

Topic: Undefined Setup/Loop Issue (Read 252 times) previous topic - next topic

Cantaloupe

I'm having a bit of trouble with a compiling error and I'm a bit lost as to what I should do.  To start, I know close to nothing about programming/programming languages.  However, I am trying to make an Arduino weather station as a gift for my husband (project GitHub is located here.) and I'm stuck at an undefined setup / undefined loop error.  Here is the code that I downloaded from the GitHub:


For the record, I have searched on the issue and I do understand that the code needs to have a loop/setup void included since the .cpp file calls for those.  However, no matter where I try to place a void, the errors continue.  For example, I've tried putting it at the beginning, like this:

Code: [Select]
#ifndef __BME280_H__
#define __BME280_H__

#if (ARDUINO >= 100)
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include <Adafruit_Sensor.h>
#include <Wire.h>

void loop(){
void setup();
}


I've tried placing it elsewhere in the code, as well, and still I get the errors.  I'm certain I must be missing something incredibly simple, but my lack of knowledge with this just has me completely lost as to what to do.  Any help would be greatly appreciated!

P.S. - I didn't post all of the code because it apparently exceeds the 9000 character limit.  Sorry!

PaulS

You need to close loop() before you start setup().
Code: [Select]

void loop()
{
}

void setup()
{
}


Do yourself a real favor, and get consistent with where you put curly braces.
The art of getting good answers lies in asking good questions.

vinceherman

When I run the Arduino development app and click new to create a new sketch, this is what I get:
Code: [Select]
void setup() {
  // put your setup code here, to run once:

}

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

}


It shows a distinct setup function and loop function.  You have one nested inside the other.

Oh, you used code tags on your first post!  YAY!!!  karma++

groundFungus

Code: [Select]
void loop(){
void setup();
}


Needs to be

Code: [Select]
void setup()
{
}

void loop()
{
}


This page may be of interest.

Cantaloupe

It shows a distinct setup function and loop function.  You have one nested inside the other.

Oh, you used code tags on your first post!  YAY!!!  karma++

Oh, this is very helpful to know.  Thank you!  Since I have been loading up code rather than writing my own, I was unaware of that!  

I have cleaned it up so that it's now like this:

Code: [Select]
#ifndef __BME280_H__
#define __BME280_H__

#if (ARDUINO >= 100)
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include <Adafruit_Sensor.h>
#include <Wire.h>

void setup()
{
}

void loop()
{
}


But I'm still getting the errors.  So that leads me to believe that I'm not placing it in the correct spot or that there's something else going on.  I'll have to poke around at it a bit more to see what I can figure out.

PaulS

Code: [Select]
#ifndef __BME280_H__
#define __BME280_H__

These are include guards for a header file. They have no place in a sketch.

Code: [Select]
#if (ARDUINO >= 100)
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

If you are writing new code, you do not need to support old versions of the IDE.
The art of getting good answers lies in asking good questions.

slipstick

If you provide a link to where exactly this code came from we might have a better chance of working out what's going on.

And a complete listing of the errors you get would also help.

Steve

Cantaloupe

#7
May 21, 2018, 10:38 pm Last Edit: May 21, 2018, 10:42 pm by Cantaloupe
If you provide a link to where exactly this code came from we might have a better chance of working out what's going on.

And a complete listing of the errors you get would also help.

Steve
I actually did link to it in my original post

(project GitHub is located here.)
Though, to be more specific, it's from the weather-station.ino file.  Maybe that's not the appropriate file for use in Sketch?    As for the complete list of errors, that's really it.  Just the two errors.  I don't know that it helps, but here's the output anyway.

Code: [Select]
core.a(main.cpp.o): In function `main':
/usr/share/arduino/hardware/arduino/cores/arduino/main.cpp:11: undefined reference to `setup'
/usr/share/arduino/hardware/arduino/cores/arduino/main.cpp:14: undefined reference to `loop'
collect2: error: ld returned 1 exit status


Edit:  Foolish me, I didn't link directly to the .ino file like I had intended.  Fixed it, though!

pert

#8
May 21, 2018, 10:52 pm Last Edit: May 21, 2018, 10:52 pm by pert
Please do this:
  • File > New
  • Sketch > Verify/Compile

Does an error occur?

Cantaloupe

Please do this:
  • File > New
  • Sketch > Verify/Compile

Does an error occur?
It does.  Hm...is something not pointing to the correct place, then?

PaulS

It does.  Hm...is something not pointing to the correct place, then?
Post the code YOU get when you use File + New.

Use File + Preferences, and click the Verbose mode for compilation checkbox. Post the complete output.
The art of getting good answers lies in asking good questions.

slipstick

Try attaching the code that you're trying to compile to a post as described in "How to use this forum - please read".

The weather.ino that I just picked up from your link doesn't contain anything like the code you posted in your first post. I haven't got all the libraries needed to compile it and I can't be bothered to try to find them all but it definitely does contain both setup() and loop().

Steve

Cantaloupe

Ok, so I've attached both the weather-station.ino file that I've been having the problem with and the error output when creating a new Sketch (File > New) and then running Verify/Compile.  I hope this helps!

pert

You're using an extremely outdated version of the Arduino IDE, probably because you installed it via a Linux package manager. Please download and install the official version of the Arduino IDE from:
http://www.arduino.cc/en/Main/Software

Cantaloupe

You're using an extremely outdated version of the Arduino IDE, probably because you installed it via a Linux package manager. Please download and install the official version of the Arduino IDE from:
http://www.arduino.cc/en/Main/Software
And this solved it, thank you!  I had used apt-get to quickly install Arduino IDE.  The newer version completely eliminates the error for me.  Now I can focus on all of the other errors, hah.  Thank you all so much for the help!

Go Up