diff --git a/cmake/OpenCVFindLAPACK.cmake b/cmake/OpenCVFindLAPACK.cmake
index f4f9415729de571042e0205437c9320639d7832a..684818027e6f931b78de6450858c3cb019bd3f60 100644
--- a/cmake/OpenCVFindLAPACK.cmake
+++ b/cmake/OpenCVFindLAPACK.cmake
@@ -31,7 +31,7 @@ macro(ocv_lapack_check)
   else()
     # adding proxy opencv_lapack.h header
     set(CBLAS_H_PROXY_PATH ${CMAKE_BINARY_DIR}/opencv_lapack.h)
-    if(APPLE)
+    if((APPLE OR OPENCV_SKIP_LAPACK_EXTERN_C) AND NOT OPENCV_FORCE_LAPACK_EXTERN_C)
         set(_lapack_include_str_extern_C "")
         set(_lapack_include_str_extern_C_end "")
     else()
diff --git a/cmake/checks/lapack_check.cpp b/cmake/checks/lapack_check.cpp
index 0457c44d6867c2f16583ac5aebda0c2985cc4576..6ac104b8836f06bdd13f17027097ff85ad4d5b57 100644
--- a/cmake/checks/lapack_check.cpp
+++ b/cmake/checks/lapack_check.cpp
@@ -1,3 +1,4 @@
+#include <complex.h>
 #include "opencv_lapack.h"
 
 static char* check_fn1 = (char*)sgesv_;
diff --git a/modules/core/src/hal_internal.cpp b/modules/core/src/hal_internal.cpp
index d98cd303c4028e2459c73a481e474905379fb73d..ecf5ffa489f28a3d7a89e9aa046e1cefc078d2f5 100644
--- a/modules/core/src/hal_internal.cpp
+++ b/modules/core/src/hal_internal.cpp
@@ -46,6 +46,7 @@
 
 #ifdef HAVE_LAPACK
 
+#include <complex.h>
 #include "opencv_lapack.h"
 
 #include <cmath>