http://www.vex.net/~trebla/haskell/so.xhtml describes how to compile shared library.
About compiling command:
ghc -O2 -dynamic -shared -fPIC -o libEv
Since Kaiko contacted me privately for an answer, might as well post it here...
By omitting -dynamic you would be trying to take all the static .a libs and link them into one massive .so file. Those .a libs were themselves built without -fPIC. All code that ends up on a .so file must be built with -fPIC (at least on ELF x86-64). Thus the linking would fail in this case because -fPIC is required but the libs were not built with -fPIC.
There are a few things that vary between different ways of building static and dynamic libraries:
In principle, lots of different combinations of these things make sense but in practice only a few are used.
On Linux (ELF), there are two standard approaches to building libraries, fully static and fully dynamic. In the fully static approach the answer to question 1,2,3 above are: .a archive, no -fPIC, same DSO. In the fully dynamic approach the answers are: .so lib, -fPIC, external DSO.
Now what you want to do is different. You want all libraries to be built as .a files, but with -fPIC and external symbols expected to be in the same DSO. This would then let you link all those libraries together into one huge shared library. So the crucial difference is the use of -fPIC, since on ELF (specifically x86_64) code that ends up in a shared lib must be built with -fPIC.
By contrast, on Windows, GHC can do exactly what you want, to link all the Haskell libs (including the RTS etc) into one massive shared lib (.dll). This is because on Windows (unlike ELF), position independent code does not matter. So on Windows, one is able to take the static libraries and link them into a big shared library.
In principle this should also be possible on Linux, if all of the Haskell libraries were built statically but with -fPIC. This is not the default, and that is the immediate reason why you cannot omit -dynamic in this case on Linux.
So in principle, one could try rebuilding ghc and the core libraries from source using the -fPIC flag and then see if it then works to omit -dynamic and link everything into one huge shared lib.