While compiling, MinGw throws an error:undefined reference to .... How can I fix this?
It's compiling just fine. It's linking that is having a problem.
An undefined reference to X means you haven't linked in the object or archive file that defines X.
Link to it.