Fix libdl detection on FreeBSD.

Refs #4977
Merge branch 'feature/libdl-freebsd-4977' into next

Fixes #4977