Error while compiling: "undefined reference to loop"

Hello, i know this is probably not the place to put this but i am in dire need of help. i am quite new to ardinou and ive got a problem which im struggling to find the cause of. Ive downloaded current versions of drivers aswell as Ardinou IOT. Can anyone help me with this error as im not actually sure what its referring to.
All the code is trying to do is connect to the internet and output a message to say its successful. I am using a NodeMCU.
`//USING A NODEMCU TO TRAIL CONNECTING TO WIFI, NOT WORKING AT ALL, KEEP GETTING ERROR MESSAGE WHICH APPEARS AT THE BOTTOM//
//TRIED INSTALLING MANY DRIVERS INCLUDING THE ESP8266.H,DHT,ADAFRUIT... NOTHING WORKS//

#include <ESP8266WiFi.h>

  const char * ssid= "{redacted}";
  const char * password= "{redacted}";

  int ledPin=13;

void setup() {
 pinMode(ledPin,OUTPUT);
 digitalWrite(ledPin,LOW);

Serial.begin(115200);
Serial.println();
Serial.print("Wifi connecting to ");
Serial.println(ssid);

WiFi.begin(ssid , password);

Serial.println();
Serial.print("connecting");

while( WiFi.status() != WL_CONNECTED ){
  delay(500);
  Serial.print(".");
}
digitalWrite(ledPin,HIGH);
Serial.println();
}
/Users/alexmarkham/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: /private/var/folders/td/xrdny6fd307g12t9r8vp_gcc0000gn/T/arduino/sketches/77C3C0DE0834D07A72E8DF362DFA5C31/core/core.a(core_esp8266_main.cpp.o): in function `__loop_end':
/Users/alexmarkham/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/cores/esp8266/core_esp8266_main.cpp:245: undefined reference to `loop'
/Users/alexmarkham/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: /private/var/folders/td/xrdny6fd307g12t9r8vp_gcc0000gn/T/arduino/sketches/77C3C0DE0834D07A72E8DF362DFA5C31/core/core.a(core_esp8266_main.cpp.o): in function `_ZL12loop_wrapperv':
/Users/alexmarkham/Library/Arduino15/packages/esp8266/hardware/esp8266/3.1.2/cores/esp8266/core_esp8266_main.cpp:250: undefined reference to `loop'
collect2: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

Moderator edit: password redacted; code tags added

Hello alexmnoobie

Welcome to the worldbest Arduino forum ever.

Don't hijack this thread.

Open a new topic with all the necessary information about your project and you will be helped.

The loop() function is missing in the sketch.

Have a nice day and enjoy coding in C++.

Yup. And yet, here we are. An overworked moderator having to tidy up.

Please do not post passwords on the forum.

Thread split.

Hi @alexmnoobie. Every Arduino sketch must have a setup function and a loop function. When the loop function is missing from the sketch, as is the case with the sketch you shared here, you get this "undefined reference to 'loop'" error.

So the solution is to add the missing required function. If you don't have any code that needs to be put in the function, you can simply leave it empty:

void loop() {
}

Okay thank you and now it says that Wifi does not have a name type?

I have merged your cross-posts @alexmnoobie.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Okay thank you and now it says that Wifi does not have a name type?

Please show your revised code

at the end of your code, right down the bottom put this

void loop()
{
}

compile
does it work now ?

type or paste code here#include <ESP8266WiFi.h>

  const char * ssid= "";
  const char * password= "";

  int ledPin=13;

void setup() {
 pinMode(ledPin,OUTPUT);
 digitalWrite(ledPin,LOW);

Serial.begin(115200);
Serial.println();
Serial.print("Wifi connecting to ");
Serial.println(ssid);
}

WiFi.begin(ssid , password);

Serial.println();
Serial.print("connecting");

while(WiFi.status() != WL_CONNECTED ){
  delay(500);
  Serial.print(".");
}
digitalWrite(ledPin,HIGH);
Serial.println();
void loop()
{
}

/Users/alexmarkham/Documents/Arduino/ESPTEST/ESPTEST.ino:21:1: error: 'WiFi' does not name a type
21 | WiFi.begin(ssid , password);
| ^~~~
/Users/alexmarkham/Documents/Arduino/ESPTEST/ESPTEST.ino:23:1: error: 'Serial' does not name a type
23 | Serial.println();
| ^~~~~~
/Users/alexmarkham/Documents/Arduino/ESPTEST/ESPTEST.ino:24:1: error: 'Serial' does not name a type
24 | Serial.print("connecting");
| ^~~~~~
/Users/alexmarkham/Documents/Arduino/ESPTEST/ESPTEST.ino:26:1: error: expected unqualified-id before 'while'
26 | while(WiFi.status() != WL_CONNECTED ){
| ^~~~~
/Users/alexmarkham/Documents/Arduino/ESPTEST/ESPTEST.ino:30:13: error: expected constructor, destructor, or type conversion before '(' token
30 | digitalWrite(ledPin,HIGH);
| ^
/Users/alexmarkham/Documents/Arduino/ESPTEST/ESPTEST.ino:31:1: error: 'Serial' does not name a type
31 | Serial.println();
| ^~~~~~
/Users/alexmarkham/Documents/Arduino/ESPTEST/ESPTEST.ino:32:1: error: expected unqualified-id before '{' token
32 | {
| ^

exit status 1

Compilation error: 'WiFi' does not name a type```
type or paste code here

still doesnt work as its asking for a name type for serial and Wifi

All of that needs to be in setup()

1 Like

Copy and try this

#include <ESP8266WiFi.h>

const char * ssid = "{redacted}";
const char * password = "{redacted}";

int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  Serial.begin(115200);
  Serial.println();
  Serial.print("Wifi connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  Serial.println();
  Serial.print("connecting");

  while ( WiFi.status() != WL_CONNECTED ) {
    delay(500);
    Serial.print(".");
  }
  digitalWrite(ledPin, HIGH);
  Serial.println();
}

void loop() {

}

The curly bracket to close setup() was at a wrong place in your sketch ... :wink:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.