Compiling cocos2d-x and FreeImage. Resolving common libraries

Hi,
Has anyone tried integrating FreeImage with cocos2d-x ? There are lots of common libraries between the two such as ‘libjpg’, ‘libpng’, ‘libtiff’, ‘libxml2’, etc.
I tried compiling the two together but got lots of ‘first defined here’ and ‘multiple definitions errors’. Any pointers as to how I can resolve this?