1

I am trying to build OpenCV in a Python virtual environment, because some code uses Python 2.7 and wants OpenCV 3.1.0, which isn't necessarily the configuration the system has/needs. Thus, I thought a little installation script deploying a custom OpenCV in a virtual environment would be nice.

This is my CMAKE routine (indented for readability):

cmake -D BUILD_TIFF=ON 
      -D BUILD_opencv_java=OFF
      -D CMAKE_BUILD_TYPE=RELEASE
      -D CMAKE_INSTALL_PREFIX=${env_path/local}
      -D PYTHON_EXECUTABLE=${env_path}/bin/python
      -D PYTHON_INCLUDE_DIR=${env_path}/include/python2.7 
      -D PYTHON_PACKAGES_PATH=${env_path}/lib/python2.7/site-packages
      -D INSTALL_PYTHON_EXAMPLES=ON
      ${opencv_source_dir}

${env_path} is the path to the virtual environment and ${opencv_source_dir} the path to the (unpacked) OpenCV source files.

When my script hits the actual building:

make -j4
make install

I always end up with this error:

/usr/include/c++/6.1.1/cstdlib:75:25: (...) stdlib.h: (...) not found
#include_next <stdlib.h>
                        ^

However, the file actually is there:

sudo find / -type f -name "*stdlib.h"

returns:

/usr/include/stdlib.h
/usr/include/bits/stdlib.h
/usr/include/bsd/stdlib.h
/usr/include/freetype2/freetype/config/ftstdlib.h
/usr/include/c++/6.1.1/stdlib.h
/usr/include/c++/6.1.1/tr1/stdlib.h

The only link I found via Google (GCC Bugzilla – Bug 70129) isn't really helping?!

Has anyone experienced the same error?

How can I force CMAKE to use gcc/g++ 5 rather than 6? (I found some links that had no answer why this error happens...but they suggest to use gcc/g++ 5 for compilation, because the error does not occur there)

daniel451
  • 10,626
  • 19
  • 67
  • 125
  • See the discussion here for multiple versions of compiler: http://stackoverflow.com/questions/17275348/how-to-specify-new-gcc-path-for-cmake – Robert Prévost Sep 11 '16 at 21:14
  • Thanks! Now I am building OpenCV with `gcc-5` and `g++-5` and this seems to work (compiles without errors, just some warnings). Doing `import cv2` inside the virtual environment works :) – daniel451 Sep 11 '16 at 21:43

0 Answers0