fix implicit declarations which truncate pointers on 64bit

and some places where header inclusions were missing (requires
double-inclusion guards in some of the affected headers).