The GCC linker may scan libraries in the order they are on the command line, which means for you it may scan the libraries first and sees no one using them, and therefore you get the errors. To be sure, place the libraries last on the command line:
gcc hw_opengl.cpp -o hw_opengl -lGL -lGLU -lglut