opencv: failed on Configuring with M1 Mac

System Information

OpenCV version: 4.5.2 CMakeError.log CMakeOutput.log

Operating System / Platform: macOS Monterey 12.5 Apple M1 Compiler & compiler version: XCode 14.0.1 Python version: 3.10 CMake: 3.25.1

Detailed description

I tried to solve this problem for a week…

-- Check size of size_t
CMake Error at /opt/homebrew/Cellar/cmake/3.25.1/share/cmake/Modules/CheckTypeSize.cmake:148 (try_compile):
  Cannot copy output executable

    ''

  to destination specified by COPY_FILE:

    '/Users/zhaoweiwang/opencv/ios/build/build-arm64-iphoneos/CMakeFiles/CheckTypeSize/SIZEOF_SIZE_T.bin'

  Recorded try_compile output location doesn't exist:

    /Users/zhaoweiwang/opencv/ios/build/build-arm64-iphoneos/CMakeFiles/CMakeScratch/TryCompile-2PaoqU/Release/cmTC_7e257.app/cmTC_7e257

Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.25.1/share/cmake/Modules/CheckTypeSize.cmake:278 (__check_type_size_impl)
  3rdparty/libjpeg-turbo/CMakeLists.txt:25 (check_type_size)


-- Check size of unsigned long
CMake Error at /opt/homebrew/Cellar/cmake/3.25.1/share/cmake/Modules/CheckTypeSize.cmake:148 (try_compile):
  Cannot copy output executable

    ''

  to destination specified by COPY_FILE:

    '/Users/zhaoweiwang/opencv/ios/build/build-arm64-iphoneos/CMakeFiles/CheckTypeSize/SIZEOF_UNSIGNED_LONG.bin'

  Recorded try_compile output location doesn't exist:

    /Users/zhaoweiwang/opencv/ios/build/build-arm64-iphoneos/CMakeFiles/CMakeScratch/TryCompile-pJTmFi/Release/cmTC_8bb7b.app/cmTC_8bb7b

Call Stack (most recent call first):
  /opt/homebrew/Cellar/cmake/3.25.1/share/cmake/Modules/CheckTypeSize.cmake:278 (__check_type_size_impl)
  3rdparty/libjpeg-turbo/CMakeLists.txt:26 (check_type_size)



-- General configuration for OpenCV 4.5.2 =====================================
--   Version control:               unknown
-- 
--   Platform:
--     Timestamp:                   2023-01-19T16:22:16Z
--     Host:                        Darwin 21.6.0 arm64
--     Target:                      iOS 9.0 arm64
--     CMake:                       3.25.1
--     CMake generator:             Xcode
--     CMake build tool:            /Users/zhaoweiwang/opencv/ios/build/build-arm64-iphoneos/xcodebuild_wrapper
--     Xcode:                       14.0.1
--     Configuration:               Debug Release
-- 
--   CPU/HW features:
--     Baseline:                    NEON FP16
--       requested:                 DETECT
-- 
--   C/C++:
--     Built as dynamic libs?:      NO
--     C++ standard:                11
--     C++ Compiler:                /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++  (ver 14.0.0.14000029)
--     C++ flags (Release):         -fembed-bitcode   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fembed-bitcode   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
--     C flags (Release):           -fembed-bitcode   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fembed-bitcode   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments -Wno-semicolon-before-method-body  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      
--     Linker flags (Debug):        
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          -framework UIKit -framework Accelerate -framework CoreGraphics -framework QuartzCore
--     3rdparty dependencies:       libprotobuf libjpeg-turbo libwebp libpng zlib quirc ade
-- 
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objc objdetect photo stitching video videoio world
--     Disabled:                    -
--     Disabled by dependency:      -
--     Unavailable:                 java python2 python3 ts
--     Applications:                -
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI: 
-- 
--   Media I/O: 
--     ZLib:                        build (ver 1.2.11)
--     JPEG:                        build-libjpeg-turbo (ver 2.0.6-62)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     AVFoundation:                YES
--     iOS capture:                 YES
-- 
--   Parallel framework:            GCD
-- 
--   Trace:                         YES (built-in)
-- 
--   Other third-party libraries:
--     Custom HAL:                  NO
--     Protobuf:                    build (3.5.1)
-- 
--   Python (for build):            NO
-- 
--   Objective-C wrappers:          YES
-- 
--   Install to:                    /Users/zhaoweiwang/opencv/ios/build/build-arm64-iphoneos/install
-- -----------------------------------------------------------------
-- 
-- Configuring incomplete, errors occurred!
See also "/Users/zhaoweiwang/opencv/ios/build/build-arm64-iphoneos/CMakeFiles/CMakeOutput.log".
See also "/Users/zhaoweiwang/opencv/ios/build/build-arm64-iphoneos/CMakeFiles/CMakeError.log".
============================================================
ERROR: Command '['cmake', '-GXcode', '-DAPPLE_FRAMEWORK=ON', '-DCMAKE_INSTALL_PREFIX=install', '-DCMAKE_BUILD_TYPE=Release', '-DOPENCV_INCLUDE_INSTALL_PATH=include', '-DOPENCV_3P_LIB_INSTALL_PATH=lib/3rdparty', '-DFRAMEWORK_NAME=opencv2', '-DIOS_ARCH=arm64', '-DCMAKE_TOOLCHAIN_FILE=/Users/zhaoweiwang/opencv/opencv/platforms/ios/cmake/Toolchains/Toolchain-iPhoneOS_Xcode.cmake', '-DCPU_BASELINE=DETECT', '/Users/zhaoweiwang/opencv/opencv', '-DCMAKE_C_FLAGS=-fembed-bitcode', '-DCMAKE_CXX_FLAGS=-fembed-bitcode']' returned non-zero exit status 1.
============================================================
Traceback (most recent call last):
  File "/Users/zhaoweiwang/opencv/opencv/platforms/ios/build_framework.py", line 159, in build
    self._build(outdir)
  File "/Users/zhaoweiwang/opencv/opencv/platforms/ios/build_framework.py", line 133, in _build
    self.buildOne(target[0], target[1], main_build_dir, cmake_flags)
  File "/Users/zhaoweiwang/opencv/opencv/platforms/ios/build_framework.py", line 284, in buildOne
    execute(cmakecmd, cwd = builddir)
  File "/Users/zhaoweiwang/opencv/opencv/platforms/apple/cv_build_utils.py", line 13, in execute
    retcode = check_call(cmd, cwd = cwd)
  File "/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '-GXcode', '-DAPPLE_FRAMEWORK=ON', '-DCMAKE_INSTALL_PREFIX=install', '-DCMAKE_BUILD_TYPE=Release', '-DOPENCV_INCLUDE_INSTALL_PATH=include', '-DOPENCV_3P_LIB_INSTALL_PATH=lib/3rdparty', '-DFRAMEWORK_NAME=opencv2', '-DIOS_ARCH=arm64', '-DCMAKE_TOOLCHAIN_FILE=/Users/zhaoweiwang/opencv/opencv/platforms/ios/cmake/Toolchains/Toolchain-iPhoneOS_Xcode.cmake', '-DCPU_BASELINE=DETECT', '/Users/zhaoweiwang/opencv/opencv', '-DCMAKE_C_FLAGS=-fembed-bitcode', '-DCMAKE_CXX_FLAGS=-fembed-bitcode']' returned non-zero exit status 1.

Steps to reproduce

cd ~/<my_working_directory>
python opencv/platforms/ios/build_framework.py ios

run the code above can reproduce

Issue submission checklist

  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 34 (12 by maintainers)

Most upvoted comments

I found this useful thread in CMake repository, there are some suggestions: https://gitlab.kitware.com/cmake/cmake/-/issues/24257

Unfortunately I can’t check them (no H/W access).

Could you try this quick workaround:

  • export OPENCV_SKIP_XCODEBUILD_FORCE_TRYCOMPILE_DEBUG=1
  • and run from clean build directory

Looks like it passes CMake on second run and moves forward (it is strange).

From provided log:

env: python: Not a directory

There is missing python executable. It was replaced with python3 on OSX (but without any symlink).

CMake’s find_package() is not able to properly work with that:

-- Python (for build): NO

  1. Try to create and activate some python’s virtualenv (not sure about OSX, but venv creates “python” symlink on Linux):
$ python3 -m venv pyenv
$ source ./pyenv/bin/activate
$ python --version  # <--- check this
  1. Alternative workaround is adding here: https://github.com/opencv/opencv/blob/4.7.0/platforms/ios/build_framework.py#L198

    • -DPYTHON_DEFAULT_EXECUTABLE=python3
  2. Another workaround is creating python -> python3 symlink somewhere in /usr/local/bin (check your PATH variable).

I am facing the exact problem when trying to run build_framework.py ios. The script passed CMake after the second try. However, I got another error:

.../third_party/opencv-4.7.0/3rdparty/libjpeg-turbo/src/jdhuff.h:77:19: error: invalid token at start
      of a preprocessor expression
#if SIZEOF_SIZE_T == 8 || defined(_WIN64)

I think it is related to the original issue from OP log, something wrong when CMake checks size_t.

Perhaps there is a problem with CMake or with CMake’s toolchains for Apple.

Unfortunately, I can’t say more, because I don’t observe that problem. There is example of CI build for iOS: https://github.com/opencv/opencv/actions/runs/4019786615/jobs/6907022279 (and there is Configuration: Debug Release which doesn’t trigger a problem)

@alalek I briefly checked a full log in iOS section. Looks like CI runs on very outdated setup.

CMake: 3.20.1 when currently the latest version is 3.25.2 Xcode: 12.5 when current the latest version is 14.2 (the problem is that even if I download 12.5 version of Xcode it couldn’t launch on macOS Ventura. It’s really hard to find someone who work on such outdated setup to try to run script in similar conditions)

For CMake 3.26.4 (opencv 4.7.0-dev), I had to use:

export OPENCV_SKIP_XCODEBUILD_FORCE_TRYCOMPILE_DEBUG=1

as mentioned in:

https://github.com/opencv/opencv/pull/13912

@asmorkalov Actually no.

There was a CMake-related bug. And there is OpenCV workaround for that bug. But that active OpenCV workaround doesn’t work anymore with the latest CMake. Need to investigate and tune condition for enabling of OpenCV workaround for old CMake versions only.

related PR with workaround: #13912

  • CMake < 3.25: keep using workaround
  • CMake == 3.25.0: emit error to upgrade CMake to 3.25.1
  • CMake >= 3.25.1: disable OpenCV workaround.

After 2 days of frustration, I’ve finally compiled the code with no error.

OpenCV version: 4.7.0 Operating System / Platform: Macbook Pro (2019), Ventura 13.0 Compiler & compiler version: XCode 14.2 (14C18) Python version: 3.7.6 CMake: 3.24.0

Looks like that SIZEOF_SIZE_T value is undefined/empty. That triggers an error.

Could you patch WITH_JPEG value to bypass related code (see comment above) and try from the clean build directory?

@alalek thanks for your help.

I’ve chosen another workaround, by downgrading CMake to 3.20.1, the error related to size_t disappeared.

Looks like it passes CMake on second run and moves forward (it is strange).

From provided log:

env: python: Not a directory

There is missing python executable. It was replaced with python3 on OSX (but without any symlink).

CMake’s find_package() is not able to properly work with that:

-- Python (for build): NO

  1. Try to create and activate some python’s virtualenv (not sure about OSX, but venv creates “python” symlink on Linux):
$ python3 -m venv pyenv
$ source ./pyenv/bin/activate
$ python --version  # <--- check this
  1. Alternative workaround is adding here: https://github.com/opencv/opencv/blob/4.7.0/platforms/ios/build_framework.py#L198
  • -DPYTHON_DEFAULT_EXECUTABLE=python3
  1. Another workaround is creating python -> python3 symlink somewhere in /usr/local/bin (check your PATH variable).

@alalek I don’t know exactly 1st or 2nd step helped or maybe both of them but I finally got a successful result. Thank you a lot for the help. Maybe I can send some error logs or do anything else to find the problem and prevent such situations for others?

something wrong when CMake checks size_t.

@dangkhoasdc Could you check value of SIZEOF_SIZE_T in CMakeCache.txt or CMakeVars.txt files? (after the first and the second run)

Result from CMakeCache.txt (1st run):

//Have symbol posix_memalign
HAVE_POSIX_MEMALIGN:INTERNAL=1
//Result of TRY_COMPILE
HAVE_SIZEOF_SIZE_T:INTERNAL=TRUE

On a related note, I’ve found this post suggesting that this is an issue from CMake: https://forum.dcmtk.org/viewtopic.php?p=21396

@alalek thanks for your suggestion, but unfortunately these changes (commented line) don’t affect it. The same problem. Please specify which error/s file/s I should attach for the details?