you use references to cv::Mat, not cv::Mat itself. Just try to move this include to precomp.hpp and build it