There is no command that will work on all distros since package management systems vary.
For software that supports pkg-config, you can probably use something like this on most distro's:
pkg-config --modversion gtk+-2.0
Tricky thing is that you have to know what software comes with pkg-config files (the files in /usr/lib/pkgconfig). You can get a list of those with
or if you want them sorted alphabetically,
pkg-config --list-all | sort