The problem was that Arduino.h (which contains HardwareSerial) is a C++ library. So when I tried to include it in a C file, it gave an error.
Changing the file extension from .c to .cpp fixed the issue.