New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Needs universal framework build on macOS Big Sur #18049
Comments
@komakai could you help with the issue? |
I believe CAROTENE was contributed by NVIDIA - maybe they could help get it to work on Apple Silicon. If I'm correct it contains optimization for ARM processors so it would definitely be good to fix this
The iOS build script is creating a Universal build script - so we could probably copy ideas from their
Looks like adding a cast somewhere would fix that 2 and 3 I can probably take a look at but I don't have a machine running Big Sur beta yet so it will take a while to get myself set up. |
Carotene library contains functions implementations with ARM NEON intrinsics. There is nothing specific to NVIDIA, it should be just general compilation issue. |
The log from: There is one line error message about missing |
Carotene compilation should've been fixed here: #17987 Please try latest 3.4 or master branch version. |
I use the DTK to build the framework for arm64 on master without any issue. And test on the different machines with the same environment:
DTK:
Intel mac:
|
To build for arm64 on Intel machine, you have to provide cmake toolchain file for cross-compilation or pass the following parameters:
Probably something similar is required for cross-compilation on DTK for IA, but I don't have this system and can not test it. |
@MainasuK I had a look at the macOS build scripts and there is a possibility that just the following simple change could work: Could you try building with that change and with the below command line?
|
@MainasuK Ah sorry - this patch is not enough. We will need to create something equivalent to the |
@komakai The same error when building x86_64 on the DTK. And If the --archs set as Disable NEON: def getCMakeArgs(self, arch, target):
args = [
"cmake",
"-GXcode",
"-DAPPLE_FRAMEWORK=ON",
"-DENABLE_NEON=OFF", <<<< add this
"-DCMAKE_INSTALL_PREFIX=install",
"-DCMAKE_BUILD_TYPE=%s" % self.getConfiguration(),
"-DOPENCV_INCLUDE_INSTALL_PATH=include",
"-DOPENCV_3P_LIB_INSTALL_PATH=lib/3rdparty",
"-DFRAMEWORK_NAME=%s" % self.framework_name,
... I use that command to make the universal framework without error. Framework and build log upload to Dropbox. Check archs: % lipo -archs opencv2.framework/opencv2
x86_64 arm64 Maybe could disable CAROTENE and NEON for x86_64 build only. Because they are ARM only. And I make a universal build for my side-project ImageReader with the universal framework. The app natively running on the DTK and Intel mac without any issue. Only crash when using Rosetta and that's doesn't matter. Thanks a lot and I'm glad to help if needs building tests. |
I downloaded Xcode 12 beta4 and had another attempt at this: |
I try to build the universal framework with the new commit on the DTK. And the camke report a configure error and returned. DTK-build.log I notice when building x86_64 the log says:
Maybe "-DCPU_BASELINE=DETECT" not mark the NEON off. So I add this just after your changes.
Then the universal build works. And I'm trying to use the framework and see if have any error. Update it soon. Update: |
@MainasuK thanks for testing - I'll make a PR now |
@MainasuK could you try building komakai@fdcbd8d on the DTK and see if the x86_64 build works correctly? |
I test the new commit. The universal framework built on the DTK works. |
@MainasuK thanks for testing - looks like the new patch is an improvement on the first attempts |
Hi, I'm working on getting a macOS app compiling on Silicon and I'm having some trouble building OpenCV for arm64. I'm using the CMake app to build the dylibs (we don't need the entire framework) and I'm using the 4.5.0-openvino release. Is this supported as of that release? If so, I have some more questions below the fold. If not, is that coming soon? The first problem is I don't seem to be able to compile for x86 and arm at the same time. I just get The second is if I try to build for just arm, I immediately get compilation errors when I attempt to
My command line tools are pointed at Xcode 12.2 beta 2 and I'm on Catalina. Do I need to be on Big Sur / the DTK to compile this? Any help would be appreciated! (also if this isn't the best place for this discussion, I'd be happy to move it elsewhere.) |
@LGriffioen building with this command line is known to work (i.e. produce a universal binary): If you are building some other way then your results may vary. @alalek any chance you could add "Support for Apple Silicon" to the ChangeLog for release 4.5 ? (Much appreciated!) |
I wrote a comprehensive blog post that shows how to build and install OpenCV on an M1 MacBook - https://sayak.dev/install-opencv-m1/. Hopefully, it turns out to be useful. |
@sayakpaul Hi I'm facing this problem, do you know how to solve this?
|
It likely linked with an x86_64 version of libpng. You'll need to install the dependencies to different locations. The current convention is installing arm64 libraries using a homebrew instance under Then you can simply switch your library and include paths using compiler and linker flags. Official homebrew advice on multiple installs (and specifically ARM vs Intel): https://docs.brew.sh/Installation#alternative-installs Quick Example1 - This command will create the second homebrew installation for you:
2 - You then install the dependencies using:
You then just need to switch |
System information (version)
Detailed description
I found a temporary workaround to build arm64 opencv2.framework on the DTK with Apple Silicon. And cross build should works but the try failed on the intel machine. (Intel and Apple Silicon could build arm64 & x86_64. Both could run x86_64 (via Rosetta). But arm64 running is Apple Silicon only).
Prepare:
brew install -s cmake
With:
Build:
% ./opencv-4.4.0/platforms/osx/build_framework.py ./opencv-framework-4.4.0 --contrib ./opencv_contrib-4.4.0 --enable_nonfree --disable CAROTENE
Test:
% ./opencv-4.4.0/platforms/osx/run_tests.py --framework_dir=/Users/mainasuk/Developer/opencv-framework-4.4.0 --framework_name=opencv2 /Users/mainasuk/Developer/opencv-framework-4.4.0/build/build-arm64-macosx/modules/objc/test
/Users/mainasuk/Developer/opencv-framework-4.4.0/build/build-arm64-macosx/modules/objc/test_build
pointsIn
with type[Point2d]
and pointsOut with[Point2f]
I have a Swift port repo for OpenCV. After create folder "Frameworks" under the root and move the opencv2.framework into it. All demo program in
OpenCVBridge.xcodeproj
run identically as the Intel Mac.And here are 3 problems for that.
I hope that transform will not so hard.
The text was updated successfully, but these errors were encountered: