Thank you for the prompt reply @zoziha. I solved the issue. It looks like I was providing the wrong library path to the compiler; the code runs properly now.
Thank you for trying out the sample program yourself though, it helped knowing that there was nothing wrong with it.