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. The stack allocations were causing the application to crash on my system.

#### Remaining issues
I still can't get a proper dng file out of HDRMerge, even using a non-Sony camera's raw files. As a platform-agnostic test, I tried uploading the produced dng's to Google Plus and it rejects them.