Error compiling OpenCV, fatal error: stdlib.h: No such file or directory

Try by disabling pre-compiled headers, either from cmake-gui or using the command line parameter

-DENABLE_PRECOMPILED_HEADERS=OFF

Compiling from zip package (opencv-2.4.11) did not work for me but the latest version* from github repo gave me a successful build on ubuntu 17.04

git clone https://github.com/opencv/opencv.git
cd opencv
mkdir mybin
cd mybin
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DENABLE_PRECOMPILED_HEADERS=OFF -DWITH_FFMPEG=OFF ..
make
sudo make install

Update: You might want to do git checkout 3.4 after git clone because the master branch has many new changes since I wrote this

Note: ffmpeg is deprecated and optional so I have used WITH_FFMPEG=OFF flag
Update: I could build with ffmpeg on 18.04, used WITH_FFMPEG=ON flag. Latest ffmpeg should work with 17.04 as well. Comment down if you were successful!

*OpenCV commit id cca99bf8249387da9f79be8d549b2d49e39a0289

Additional info: Dependencies I installed before compiling-

build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libtbb2 libtbb-dev

Hope this helps someone in future!


I am on Manjaro Linux and this problem do exists on my system because of TBBConfig.cmake file which is a part of Intel-TBB library and contains modification to path of include folder path at line 56:

set_target_properties(TBB::${_tbb_component} PROPERTIES
                                  INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/../../../include")

While -DENABLE_PRECOMPILED_HEADERS=OFF was already off in my case and didn't fix the issue, it seems that this flag -DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON fixes it.