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'

  • Sounds like you have some corruption in the file. Try reinstalling.
    – Majenko
    Jan 24, 2016 at 16:00
  • you mean retry installing the library ? @Majenko
    – yash jain
    Jan 24, 2016 at 16:53
  • Or the whole IDE since it comes with the IDE
    – Majenko
    Jan 24, 2016 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, 2016 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, 2016 at 20:33

2 Answers 2


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.

  • 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, 2016 at 7: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. Jan 26, 2016 at 19:17

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.