Fix building of exes that use TH and profiling. 

Fixes #1207. Broken by @dcoutts in 02f8eef.

Combined with the hpc fix, this makes all tests pass on my machine.