Make sure you've installed both libpq-dev\
and postgresql-server-dev-all
(or specific version e.g. postgresql-server-dev-9.4
)
$ dpkg --get-selections | grep -e "libpq-dev\|postgresql-server-dev"
in case you're missing some package
apt-get install libpq-dev postgresql-server-dev-all
should fix it.