Fix compilation and thread stack size issues found on OS X

Compilation issues
---
* Compiler wasn't able to infer return type of lambdas
* Define operator<<(QString) before it is used
* Anonymous union cannot be defined in a type specifier
* Better includes
* Search for alglib3
* Remove obsolete -s linker switch (linker said it was being ignored, but it was actually causing problems)

Thread stack size
---
In two places, too much memory was being allocated on the thread stack for arrays of bytes or numbers. I moved these allocations to the heap.