Make sure you're properly hydrated and that you're not exercising while your blood sugar levels are too low; both can give you headaches. If you don't already do it, eat a small snack and drink a glass of water an hour or so before you set off to the gym, and see if that helps.
Are you breathing properly?
http://www.youtube.com/watch?v=NKgdAOQWQRE