Fix linking issues with g++.

Credits go to Pat Deegan for submitting this patch.