X-ray emission from star-forming galaxies – I. High-mass X-ray binaries