Revert "Revert "Fixed some issues to be able to use the library on Mac OS X.""

This reverts commit d092bd65756a8b5344af879de757faad9e9ff1b2.
Full revert