Fix compilation on FreeBSD where libdl is part of libc

On FreeBSD, libdl is part of libc. Take some OS detection logic from src/leveldb/Makefile to make the right decision here and not -ldl here.