build error on opencv (Ubuntu and Debian)

I have built latest source on both Debian 7.7 (wheezy) and Ubuntu 14.04.1 (trusty) using this command

makepanda/makepanda.py --verbose --everything --threads 4 --optimize 3 --installer --no-ffmpeg --no-fftw

and I’ve got this error:

...
In file included from /usr/include/opencv2/flann/flann_base.hpp:42:0,
                 from /usr/include/opencv2/flann/flann.hpp:50,
                 from /usr/include/opencv/cv.h:69,
                 from built/tmp/libp3vision_igate.cxx:18:
/usr/include/opencv2/flann/saving.h: In function ‘cvflann::IndexHeader cvflann::load_header(FILE*)’:
/usr/include/opencv2/flann/saving.h:113:63: error: exception handling disabled, use -fexceptions to enable
         throw FLANNException("Invalid index file, cannot read");
                                                               ^
In file included from /usr/include/opencv2/flann/flann_base.hpp:42:0,
                 from /usr/include/opencv2/flann/flann.hpp:50,
                 from /usr/include/opencv/cv.h:69,
                 from panda/src/vision/openCVTexture.h:33,
                 from panda/src/vision/config_vision.cxx:16,
                 from panda/src/vision/p3vision_composite1.cxx:2:
/usr/include/opencv2/flann/saving.h: In function ‘cvflann::IndexHeader cvflann::load_header(FILE*)’:
/usr/include/opencv2/flann/saving.h:113:63: error: exception handling disabled, use -fexceptions to enable
         throw FLANNException("Invalid index file, cannot read");
                                                               ^
Process exited with exit status 1 and signal code 0
The following command returned a non-zero value: g++ -ftemplate-depth-50 -fPIC -c -o built/tmp/p3vision_composite1.o -Ibuilt/tmp -Ibuilt/include -I/usr/include/python2.7 -I/usr/include/eigen3 -I/usr/include/opencv -Ipanda/src/vision -pthread -fno-exceptions -msse2 -O2 -DBUILDING_VISION panda/src/vision/p3vision_composite1.cxx
...

Which could be the issue?

After little examination, the issue seems due to FLANN ( Fast Approximate Nearest Neighbor Search Library ) module of opencv, which throw exceptions (as in /usr/include/opencv2/flann/saving.h).
I tried to uninstall libopencv-flann-dev debian package, but in this case makepanda exluded opencv support entirely.
So, for opencv support, -fno-exceptions should not be used.
I tried to set CXXFLAGS="-fexceptions" environment variable and build was successful.
Now, my question is if it is possible to set “-fexceptions” selectively only for modules which need opencv?

Thanks for the detective work! Yes, there’s an “EXCEPTIONS” option that should be added to the OPTS list of the relevant section in makepanda.py.

I just pushed something that should fix it. Thanks again.