Go Down

Topic: Ethernet WebServer Example not Compiling - 1.8.7 / Linux 64bit (Read 194 times) previous topic - next topic

LEDSchlucker

Hello, somehow, the Example sketch "WebServer" doesn't want to compile :-(

Here's the code:
Code: [Select]

/*
  Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi
 
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  //Ethernet.init(10);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Ethernet WebServer Example");

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start the server
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}



And here is the Error Msg:
Code: [Select]

Arduino: 1.8.7 (Linux), Board: "Arduino/Genuino Uno"

/tmp/ccTT56B7.ltrans1.ltrans.o: In function `IPAddress::printTo(Print&) const':
/home/username/arduino-1.8.7/hardware/arduino/avr/cores/arduino/IPAddress.cpp:108: undefined reference to `Print::print(unsigned char, int)'
/home/username/arduino-1.8.7/hardware/arduino/avr/cores/arduino/IPAddress.cpp:109: undefined reference to `Print::print(char)'
/home/username/arduino-1.8.7/hardware/arduino/avr/cores/arduino/IPAddress.cpp:111: undefined reference to `Print::print(unsigned char, int)'
/tmp/ccTT56B7.ltrans1.ltrans.o: In function `EthernetClass::socketBegin(unsigned char, unsigned int) [clone .part.1] [clone .lto_priv.65]':
/home/username/arduino-1.8.7/libraries/Ethernet/src/socket.cpp:106: undefined reference to `delayMicroseconds'
/tmp/ccTT56B7.ltrans1.ltrans.o: In function `EthernetClass::socketSend(unsigned char, unsigned char const*, unsigned int)':
/home/username/arduino-1.8.7/libraries/Ethernet/src/socket.cpp:444: undefined reference to `yield'
/home/username/arduino-1.8.7/libraries/Ethernet/src/socket.cpp:460: undefined reference to `yield'
/tmp/ccTT56B7.ltrans2.ltrans.o: In function `DNSClient::getHostByName(char const*, IPAddress&, unsigned int) [clone .constprop.26]':
/home/username/arduino-1.8.7/libraries/Ethernet/src/Dns.cpp:104: undefined reference to `millis'
/tmp/ccTT56B7.ltrans2.ltrans.o: In function `BuildRequest':
/home/username/arduino-1.8.7/libraries/Ethernet/src/Dns.cpp:157: undefined reference to `millis'
/tmp/ccTT56B7.ltrans2.ltrans.o: In function `ProcessResponse':
/home/username/arduino-1.8.7/libraries/Ethernet/src/Dns.cpp:216: undefined reference to `millis'
/home/username/arduino-1.8.7/libraries/Ethernet/src/Dns.cpp:220: undefined reference to `millis'
/home/username/arduino-1.8.7/libraries/Ethernet/src/Dns.cpp:223: undefined reference to `delay'
/tmp/ccTT56B7.ltrans2.ltrans.o:(.rodata+0x4): undefined reference to `__cxa_pure_virtual'
/tmp/ccTT56B7.ltrans2.ltrans.o:(.rodata+0x6): undefined reference to `Print::write(unsigned char const*, unsigned int)'
/tmp/ccTT56B7.ltrans2.ltrans.o:(.rodata+0xc): undefined reference to `__cxa_pure_virtual'
/tmp/ccTT56B7.ltrans2.ltrans.o:(.rodata+0xe): undefined reference to `__cxa_pure_virtual'
/tmp/ccTT56B7.ltrans2.ltrans.o:(.rodata+0x10): undefined reference to `__cxa_pure_virtual'
/tmp/ccTT56B7.ltrans2.ltrans.o:(.rodata+0x18): undefined reference to `Print::write(unsigned char const*, unsigned int)'
/tmp/ccTT56B7.ltrans2.ltrans.o:(.rodata+0x2e): undefined reference to `__cxa_pure_virtual'
/home/username/arduino-1.8.7/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main'
/tmp/ccTT56B7.ltrans0.ltrans.o: In function `EthernetClient::stop()':
/home/username/arduino-1.8.7/libraries/Ethernet/src/EthernetClient.cpp:138: undefined reference to `millis'
/home/username/arduino-1.8.7/libraries/Ethernet/src/EthernetClient.cpp:146: undefined reference to `delay'
/home/username/arduino-1.8.7/libraries/Ethernet/src/EthernetClient.cpp:147: undefined reference to `millis'
/tmp/ccTT56B7.ltrans0.ltrans.o: In function `socketSendUDP':
/home/username/arduino-1.8.7/libraries/Ethernet/src/socket.cpp:527: undefined reference to `yield'
collect2: error: ld returned 1 exit status
exit status 1
Fehler beim Kompilieren für das Board Arduino/Genuino Uno.

Dieser Bericht wäre detaillierter, wenn die Option
"Ausführliche Ausgabe während der Kompilierung"
in Datei -> Voreinstellungen aktiviert wäre.



I hope someone could help me, because I'm a beginner and do not know what to do to make it work.

pjrc

It compiles without any error here on Linux 64 bit with Arduino 1.8.7.

Here's a screenshot.


pjrc

Those errors look like 1 or more files in /home/gstafraff/arduino-1.8.7/hardware/arduino/avr/cores/arduino may be missing or corrupted.

Have you tried downloading & using a fresh copy of the Arduino IDE software?

LEDSchlucker

Thanks pjrc!
I think was an issue in the ~/arduino-1.8.7/libraries/ folder because now, after replacing the files in the libraries folder with the files out of a new download (1.8.8) it works fine.

Go Up