0

How do I rectify this error? Clearly it says there is some error in the library, so how do I correct it?

C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:1: error: expected unqualified-id before 'if'

yash jain
  • 1
  • 2
  • Sounds like you have some corruption in the file. Try reinstalling. – Majenko Jan 24 '16 at 16:00
  • you mean retry installing the library ? @Majenko – yash jain Jan 24 '16 at 16:53
  • Or the whole IDE since it comes with the IDE – Majenko Jan 24 '16 at 16:54
  • The other possibility is a syntax error in your sketch? I'm not sure how the IDE builds, but if it doesn't compile each file separately the error may come from another place and the most likely place to look is in your code. Before you reinstall take a look at the file that is generating the error and see if you notice something wrong. Just for the practice. – dlu Jan 24 '16 at 17:24
  • 1
    Which version of the IDE are you using? Please post all the output from the compiler. Please edit your post to do this and format the output using the code formatting markdown (four leading spaces). For help see Markdown help. You should be able to do this by selecting the code and pressing Ctrl+K to have your browser do this for you. – Nick Gammon Jan 24 '16 at 20:33
  • I'm not sure how the IDE builds - see How the IDE organizes things. – Nick Gammon Jan 24 '16 at 20:34
  • Show us the first handful (10 or so) of lines of the file C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp – Majenko Jan 25 '16 at 13:42
  • there is only this 1 error --- C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:1: error: expected unqualified-id before 'if' – yash jain Jan 25 '16 at 13:48
  • if (_inverse_logic ? rx_pin_read() : !rx_pin_read()) { // Disable further interrupts during reception, this prevents // triggering another interrupt directly after we return, which can // cause problems at higher baudrates. setRxIntMsk(false);
    // Wait approximately 1/2 of a bit width to "center" the sample
    tunedDelay(_rx_delay_centering);
    DebugPulse(_DEBUG_PIN2, 1);
    
    for (uint8_t i=8; i > 0; --i)
    {
      tunedDelay(_rx_delay_intrabit);
      d >>= 1;
      DebugPulse(_DEBUG_PIN2, 1);
      if (rx_pin_read())
        d |= 0x80;
    }
    
    – yash jain Jan 25 '16 at 13:53
  • First few lines of my library – yash jain Jan 25 '16 at 13:54
  • Then there is a huge chunk of the file missing - 220 lines to be precise (that is line 221 you have there). A reinstall of the IDE should have fixed it. Did you do it? – Majenko Jan 25 '16 at 15:42
  • Yeah it worked! Done compiling successfully... Can you please explain how downloading a new IDE solves the problem ? @Majenko – yash jain Jan 25 '16 at 17:16
  • The file was corrupt. You replaced it with a new copy. How it got corrupted is anyone's guess. – Majenko Jan 25 '16 at 17:26

2 Answers2

1

As you haven't shown the code that produces the error when it's compiled, I can't say for sure what the problem is. However, here are links to three instances of the same error:

error: expected unqualified-id before 'if' on stackoverflow

Arduino: error: expected unqualified-id before 'if' (using ping sensor), also on stackoverflow

error: expected unqualified-id before 'if' on arduino.cc.

In each case, the problem was due to executable code (as opposed to declarations) appearing outside of a function. You may have put some executable statements outside of loop() or setup(), etc.

James Waldby - jwpat7
  • 8,840
  • 3
  • 17
  • 32
  • Still problems related to my library...i reinstalled my IDE and in the new one SoftwareSerial.h doesnot exist..what should i do? – yash jain Jan 26 '16 at 07:16
  • You may need to separately download and install SoftwareSerial. You can get SoftwareSerial.cpp and .h from github and follow the directions at arduino.cc, Installing Additional Arduino Libraries. Note, arduino library downloads from github normally are zip files; I didn't see a zip file in this case, so adapt the instructions accordingly. – James Waldby - jwpat7 Jan 26 '16 at 19:17
0

Your copy of the SoftwareSerial library has become corrupted. Why is anyone's guess: maybe your hard drive is dying?

Replacing the file with a good copy will solve the problem. The simplest way to do that is to reinstall the IDE.

Majenko
  • 105,095
  • 5
  • 79
  • 137