bazaar compiling issue

Hey guys, to me this seems bazaar. Hopefully someone knows the reason.

Trying to compile a sketch and kept getting the "Error compiling for board Arduino/Genuino Uno." error.

I went thru my code with a fine tooth comb trying to find a mistake. Everything seemed ok to me.

The error went away and the sketch compiled properly when I defined another variable at the top, a variable which I do NOT use anywhere at all in the entire sketch. I can define the variable as an int or String, with any name at all, and the sketch compiles fine, but soon as I remove that line with the useless variable, it kicks back the error.

Thank you.

Please post your code and the full error message (both using code tags).

That sounds like a problem with the way that the IDE preprocessor adds function prototypes to your code before the compiler sees it. Adding the statement at the top of your code means that the IDE adds all its stuff immediately after it which fixes the problem. This is usually caused by one or more include statements.
Post your code anyway.

And it's bizarre - not bazaar.

Pete

Yes bizarre, thanks for the spelling lesson. I will post the code. You're probably gonna ask why I did a lot of things the way I did. Answer is because I don't know any better yet. Still learning.

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10, 0, 0, 20); 
EthernetServer server(80);  
String http_req;          
String testvariable; // this is the useless variable that seems to allow sketch to compile



void setup() {
    
    Ethernet.begin(mac, ip);  
    server.begin();           
    Serial.begin(9600);    
    pinMode(8, OUTPUT);      
}

void loop() {

EthernetClient client = server.available();  

 if (client) {  
 boolean currentLineIsBlank = true;
 while (client.connected()) {
 if (client.available()) {   
 char c = client.read(); 
 http_req += c;  
 if (c == '\n' && currentLineIsBlank) {


client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5");  // refresh the page automatically every 5 sec

//  Now send web page
                    client.println("<!DOCTYPE html>");
                    client.println("<html>");
                    client.println("<head>");
                    client.println("<title> Control Panel</title>");
                    client.println("</head>");
                    client.println("<body>");
                    client.println("<h1>PUMP Control</h1>");
                    client.println("<p>Monarch Pump</p>");
                    client.println("<form method=\"get\">");
                    PumpOnorOff(client);
                    client.println("</form>");
                    client.println("</body>");
                    client.println("</html>");

Serial.print(http_req);
http_req = "";   

                if (c == '\n') {
                currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } 
        } 
        delay(1);     
        client.stop(); 
    } // end if (client)
}
                    


void PumpOnorOff(EthernetClient cl)
{




if (digitalRead(8)==HIGH){
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_on\"checked=\"checked\"> PUMP RUN");
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_off\"onclick=\"submit();\"> PUMP OFF");
}
else if (digitalRead(8)==LOW){
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_on\"checked=\"submit();\"> PUMP RUN");
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_off\"onclick=\"checked\"> PUMP OFF");
}
}

There Error is here.

collect2.exe: error: ld returned 5 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

That doesn't look like all the error messages.

These are the errors I get with that code:

C:\Users\Peter\AppData\Local\Temp\arduino_modified_sketch_323431\sketch_dec11a.ino: In function 'void loop()':

sketch_dec11a:49: error: 'PumpOnorOff' was not declared in this scope

                     PumpOnorOff(client);

                                       ^

sketch_dec11a:74: error: a function-definition is not allowed here before '{' token

 {

 ^

sketch_dec11a:87: error: expected '}' at end of input

 }

 ^

Using library SPI at version 1.0 in folder: S:\arduino-1.6.13_1-32\hardware\arduino\avr\libraries\SPI 
Using library Ethernet at version 1.1.2 in folder: S:\arduino-1.6.13_1-32\libraries\Ethernet 
exit status 1
'PumpOnorOff' was not declared in this scope

thanks for the spelling lesson

Anytime. We aim for a fully-rounded education here :slight_smile:

Pete

Thank you Pete,

Would you mind trying the code again. I think I left some out by mistake when I copied and pasted. Not sure how that happened. Please try this code. Does this still give you many more errors than I was receiving?

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10, 0, 0, 20); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80
String http_req;          // stores the HTTP request
String test;
void setup() {
    
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for diagnostics
    pinMode(8, OUTPUT);       // LED on pin 2
}

void loop() {

EthernetClient client = server.available();  // try to get client

 if (client) {  // got client?
 boolean currentLineIsBlank = true;
 while (client.connected()) {
 if (client.available()) {   // client data available to read
 char c = client.read(); // read 1 byte (character) from client
 http_req += c;  // save the HTTP request 1 char at a time
 // last line of client request is blank and ends with \n
 // respond to client only after last line received
 if (c == '\n' && currentLineIsBlank) {
//Here is the HTML to send
//First send a standard HTTP response header

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5");  // refresh the page automatically every 5 sec

//  Now send web page
                    client.println("<!DOCTYPE html>");
                    client.println("<html>");
                    client.println("<head>");
                    client.println("<title>Irrigatioin Control Panel</title>");
                    client.println("</head>");
                    client.println("<body>");
                    client.println("<h1>PUMP Control</h1>");
                    client.println("<p>Monarch Pump</p>");
                    client.println("<form method=\"get\">");
                    PumpOnorOff(client);
                    client.println("</form>");
                    client.println("</body>");
                    client.println("</html>");

Serial.print(http_req);
http_req = "";    // finished with request, empty string
break;
 }
// every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}
                    


void PumpOnorOff(EthernetClient cl)
{
if (digitalRead(8)==HIGH){
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_on\"checked=\"checked\"> PUMP RUN");
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_off\"onclick=\"submit();\"> PUMP OFF");
}

else if (http_req.indexOf("pump_state=pump_on")>-1){
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_on\"checked=\"checked\"> PUMP RUN");
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_off\"onclick=\"submit();\"> PUMP OFF");
  digitalWrite(8,HIGH);
}
else if (digitalRead(8)==LOW){
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_on\"checked=\"submit();\"> PUMP RUN");
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_off\"onclick=\"checked\"> PUMP OFF");
}
else if (http_req.indexOf("pump_state=pump_off")>-1){
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_on\"checked=\"submit();\"> PUMP RUN");
  cl.println("<input type=\"radio\"name=\"pump_state\"value=\"pump_off\"onclick=\"checked\"> PUMP OFF");
  digitalWrite(8,LOW); 
  }
}

That code compiles. I only get a warning, which can be ignored:

S:\arduino-1.6.13_1-32\libraries\Ethernet\src\utility\socket.cpp:365:19: warning: unused parameter 's' [-Wunused-parameter]

 void flush(SOCKET s) {

                   ^

Which version of the IDE are you using?

Pete

Are you using Windows XP and/or the Windows store version of the Arduino IDE?

I am using Windows XP. Looks like Arduino IDE version 1.6.12

The most recent code I posted Pete, I just realized has the "useless" variable in there. Will it still compile for you if you remove the String test variable declaration?

Thanks,
Morgan

It still compiles when String test is commented.

Pete

hmm interesting. I just tried again with the String test commented and received the same error as always. Included the string and it compiled fine... Could it have something to do with the fact I'm using windows XP ?

Could it have something to do with the fact I'm using windows XP ?

It is quite likely that the issue is that you are using a beyond-end-of-life OS. Search the forum for the number of issues related to XP.