I was getting this same problem when compiling and it came down to not having all of the image format libraries installed, in my case it was the XPM library. I installed the XPM library and this took care of the issue, although you can also add --without-xpm to the configure options and your error should also go away.