Add support for building and using shared libraries.

Do not merge this request.