Because various distributions name packages differently, this is extremely difficult to accomplish. For instance, on Debian, a package may be named libfoo, and its counterpart development package libfoo-dev. On RHEL/CentOS it might be libfoo1 and libfoo1-devel.
A well written configure.ac (which is used to generate the 'configure' script) should tell you, in a meta way, what package you are missing. I.e.
Checking for libfoo ... no
Checking for libfoo usability .... no
./configure: Error: You are missing the package 'libfoo' and possibly
This lets you apt-cache / yum search for something to install, if the errors preceding the configure: Error: aren't obvious. Googling configure's output usually bears fruit to find out just what package you are missing.
The real problem comes when the version of libfoo your distro offers is too old for the program you are trying to compile. In that case, you must build libfoo itself, install it separately from the version provided by your distro and tell the program how to link to it (also done via 'configure')
For this reason, I usually use fast moving distributions (I.e. Ubuntu) for my development machine. Usually, I can find what I need, up to date in the universe repository.
I just had to upgrade glibc on a Debian Lenny machine just to be able to build and install a multi threaded AIO based AoE target, plus roll my own 220.127.116.11 kernel because the program wanted eventfd support. I feel your pain :)
Yet, this is part of the fun of building your own stuff .. once it works, you are doubly satisfied .. or doubly frustrated if it doesn't :)