執行完CMake以後再執行make時遇到如下錯誤html
1 [ 6%] Generating precomp.hpp.gch/opencv_core_Release.gch 2 In file included from /usr/include/c++/6/bits/stl_algo.h:59:0, 3 from /usr/include/c++/6/algorithm:62, 4 from /opt/opencv/opencv-3.1.0/modules/core/include/opencv2/core/base.hpp:53, 5 from /opt/opencv/opencv-3.1.0/modules/core/include/opencv2/core.hpp:54, 6 from /opt/opencv/opencv-3.1.0/modules/core/include/opencv2/core/utility.hpp:52, 7 from /opt/opencv/build/modules/core/precomp.hpp:49: 8 /usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: 沒有那個文件或目錄 9 #include_next <stdlib.h> 10 ^ 11 compilation terminated. 12 modules/core/CMakeFiles/pch_Generate_opencv_core.dir/build.make:62: recipe for target 'modules/core/precomp.hpp.gch/opencv_core_Release.gch' failed 13 make[2]: *** [modules/core/precomp.hpp.gch/opencv_core_Release.gch] Error 1 14 CMakeFiles/Makefile2:1178: recipe for target 'modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all' failed 15 make[1]: *** [modules/core/CMakeFiles/pch_Generate_opencv_core.dir/all] Error 2 16 Makefile:160: recipe for target 'all' failed 17 make: *** [all] Error 2
這是因爲gcc6已經吧stdlib.h歸入了libstdc++以進行更好的優化,C Library的頭文件stdlib.h使用 Include_next,而include_next對gcc系統頭文件路徑很敏感。
linux
推薦的修復方法是不要把include路徑做爲系統目錄,而是使用標準方式包含include 目錄c++
翻譯自 https://bugs.webkit.org/show_bug.cgi?id=161697git
原文說明:web
Trying to build WebKitGTK+ with GCC 6 I got this error: In file included from /home/igalia/clopez/yocto/commit-builds/meta-webkit/builds/qemux86-64/tmp-glibc/sysroots/qemux86/usr/include/c++/6.2.0/ext/string_conversions.h:41:0, from /home/igalia/clopez/yocto/commit-builds/meta-webkit/builds/qemux86-64/tmp-glibc/sysroots/qemux86/usr/include/c++/6.2.0/bits/basic_string.h:5402, from /home/igalia/clopez/yocto/commit-builds/meta-webkit/builds/qemux86-64/tmp-glibc/sysroots/qemux86/usr/include/c++/6.2.0/string:52, from /home/igalia/clopez/yocto/commit-builds/meta-webkit/builds/qemux86-64/tmp-glibc/work/i586-oe-linux/webkitgtk/2.12.5-r0/webkitgtk-2.12.5/Source/ThirdParty/ANGLE/src/common/debug.h:14, from /home/igalia/clopez/yocto/commit-builds/meta-webkit/builds/qemux86-64/tmp-glibc/work/i586-oe-linux/webkitgtk/2.12.5-r0/webkitgtk-2.12.5/Source/ThirdParty/ANGLE/src/common/mathutil.h:12, from /home/igalia/clopez/yocto/commit-builds/meta-webkit/builds/qemux86-64/tmp-glibc/work/i586-oe-linux/webkitgtk/2.12.5-r0/webkitgtk-2.12.5/Source/ThirdParty/ANGLE/src/common/mathutil.cpp:9: /home/igalia/clopez/yocto/commit-builds/meta-webkit/builds/qemux86-64/tmp-glibc/sysroots/qemux86/usr/include/c++/6.2.0/cstdlib:75:25: fatal error: stdlib.h: No such file or directory #include_next <stdlib.h> The issue seems to be that GCC 6 has now introduced stdlib.h in libstdc++ for better compliance and its including the C library stdlib.h using include_next which is sensitive to order of system header include paths. See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129 The recommended way to fix this is to stop adding include directories as system ones (-isystem) and instead use the standard way to include directories (-I) The openembedded project is carrying this downstream patch against WebKitGTK+ 2.12 with the above fix: http://git.openembedded.org/openembedded-core/tree/meta/recipes-sato/webkit/files/0001-WebKitMacros-Append-to-I-and-not-to-isystem.patch
OpenCV對gcc6支持不完善,致使gcc不兼容OpenCV優化
解決方法:卸載Ubuntu 16,使用Ubuntu 14 ui
===========================================================this
以上解法其實沒有必要,gcc6並非不能編譯OpenCV 3,加入如下編譯選項便可spa
-DENABLE_PRECOMPILED_HEADERS=OFF
知識來源:http://www.javashuo.com/article/p-tdjerjmy-s.html翻譯
感謝提供解法。