Fixes for portable libraries

This was broken on the previous refactoring, but it wasn't caught because there were no tests for it. Now there are