OpenCV Linux 安装 Make出错

执行完CMake之后再执行make时遇到以下错误

 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系统头文件路径很敏感。

推荐的修复方法是不要把include路径作为系统目录,而是使用标准方式包含include 目录

 

翻译自 https://bugs.webkit.org/show_bug.cgi?id=161697

 

原文说明:

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 

===========================================================

以上解法其实没有必要,gcc6并不是不能编译OpenCV 3,加入以下编译选项即可

-DENABLE_PRECOMPILED_HEADERS=OFF

知识来源:https://www.cnblogs.com/wuchaodzxx/p/8418980.html

感谢提供解法。

 

posted @ 2016-11-22 16:30  liutianchen  阅读(21997)  评论(0编辑  收藏  举报