Linux build fixes

Here are some fixes to make it build on Linux.

What puzzles me a bit though is why a linked context was used for OSX. Was this a concious choice, or a very quick and dirty hack?