title: Error building OpenCV: can not find 'stdlib.h'
body: <p>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.</p>
  
  <p>This is my CMAKE routine (indented for readability):</p>
  
  <pre><code>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}
  </code></pre>
  
  <p><code>${env_path}</code> is the path to the virtual environment and <code>${opencv_source_dir}</code> the path to the (unpacked) OpenCV source files.</p>
  
  <p>When my script hits the actual building:</p>
  
  <pre><code>make -j4
  make install
  </code></pre>
  
  <p>I always end up with this error:</p>
  
  <pre><code>/usr/include/c++/6.1.1/cstdlib:75:25: (...) stdlib.h: (...) not found
  #include_next &lt;stdlib.h&gt;
                          ^
  </code></pre>
  
  <p>However, the file actually <em>is</em> there:</p>
  
  <pre><code>sudo find / -type f -name "*stdlib.h"
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>/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
  </code></pre>
  
  <p>The only link I found via Google (<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129" rel="nofollow">GCC Bugzilla – Bug 70129</a>) isn't really helping?!</p>
  
  <p>Has anyone experienced the same error?</p>
  
  <p>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)</p>