how do you know that "-ldl" is needed?
Experience ;-)
In reality, the -l is passed to the linker as you would when using it on the command line. So, for a library called libfish.so, you take of the prefix "lib", and the suffix ".so", leaving you "fish". You would then import with "-lfish".
:o)