2018/4/27

opencv build error stdlib.h

cmake: fixing gcc6.x c++/stdlib.h include issue

cmake/OpenCVUtils.cmake
@@ -122,7 +122,11 @@ function(ocv_include_directories)

        OR (OPENCV_EXTRA_MODULES_PATH AND "${__abs_dir}" MATCHES "^${OPENCV_EXTRA_MODULES_PATH}"))
       list(APPEND __add_before "${dir}")
     else()
-      include_directories(AFTER SYSTEM "${dir}")
+      if (gcc_compiler_version VERSION_LESS "6.0.0")
+        include_directories(AFTER SYSTEM "${dir}")
+      else()
+        include_directories(AFTER "${dir}")
+      endif()
     endif()
   endforeach()
   include_directories(BEFORE ${__add_before})
去 https://github.com/opencv/opencv.git checkout, blame 找到 fix commit:
~/github/opencv$ git show 21d9412c93
commit 21d9412c93d0fea7c087c2cca3b232b9f8ab9d69
Author: Alexander Alekhin 
Date:   Mon Oct 3 19:38:19 2016 +0300

    cmake: fix for GCC 6.x

diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake
index aafda61ab..89a0bd578 100644
--- a/cmake/OpenCVPCHSupport.cmake
+++ b/cmake/OpenCVPCHSupport.cmake
@@ -14,12 +14,7 @@
 
 IF(CMAKE_COMPILER_IS_GNUCXX)
 
-    EXEC_PROGRAM(
-        ${CMAKE_CXX_COMPILER}
-        ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
-        OUTPUT_VARIABLE gcc_compiler_version)
-    #MESSAGE("GCC Version: ${gcc_compiler_version}")
-    IF(gcc_compiler_version VERSION_GREATER "4.2.-1" AND gcc_compiler_version VERSION_LESS "6.0.0")
+    IF(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.2.0")
         SET(PCHSupport_FOUND TRUE)
     ENDIF()
 
diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake
index 8d7c98b3e..82d82262a 100644
--- a/cmake/OpenCVUtils.cmake
+++ b/cmake/OpenCVUtils.cmake
@@ -121,6 +121,9 @@ function(ocv_include_directories)
         OR "${__abs_dir}" MATCHES "^${OpenCV_BINARY_DIR}"
         OR (OPENCV_EXTRA_MODULES_PATH AND "${__abs_dir}" MATCHES "^${OPENCV_EXTRA_MODULES_PATH}"))
       list(APPEND __add_before "${dir}")
+    elseif(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" AND
+           dir MATCHES "/usr/include$")
+      # workaround for GCC 6.x bug
     else()
       include_directories(AFTER SYSTEM "${dir}")
     endif()
@@ -142,6 +145,10 @@ endfunction()
 function(ocv_target_include_directories target)
   _ocv_fix_target(target)
   set(__params "")
+  if(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" AND
+      ";${ARGN};" MATCHES "/usr/include;")
+    return() # workaround for GCC 6.x bug
+  endif()
   foreach(dir ${ARGN})
     get_filename_component(__abs_dir "${dir}" ABSOLUTE)
     if("${__abs_dir}" MATCHES "^${OpenCV_SOURCE_DIR}"


沒有留言:

張貼留言