Okay, so if anyone is struggling with this -lGL, it basically means what it says: the linker is looking for gl.h file in a specified directory (/usr/include in my case) and it can not find it there. What you do to install gl.h: if you are rpm-based (Fedora):
sudo dnf install mesa-libGL-devel.i686 OR sudo dnf install mesa-libGL-devel.x86_64
If you are apt based:
sudo apt-get install mesa-utils
Should do.