resolve undefined references

When trying to build shared libraries on Windows (via `-DBUILD_SHARED_LIBS:BOOL=ON`), all dependencies have to be explicitly linked, no undefined references are allowed. I'm mainly using MinGW so I can do cross-compilation, but the requirement of having no undefined references can be mimicked on Linux by adding `-DCMAKE_SHARED_LINKER_FLAGS=-Wl,--no-undefined`. I posted a (long) set of logs using Ubuntu 14.04 here https://gist.github.com/tkelman/ca2dc9ee559cc2d5a0a9 where I went through, identified and fixed each undefined reference, to show how I arrived at the final patch.

I verified that this patch also works for using the MinGW compilers in Cygwin, although there are a couple of other unrelated changes that I will open separate issues for. I don't think this should cause any trouble with MSVC, but please let me know if I'm wrong there.