Fixing strange bugs appearing when building shared library on MacOS X