mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64') in Flutter
Asked Answered
S

11

40

Executing dart run ffigen got the following error:

Unhandled exception:
Invalid argument(s): Failed to load dynamic library '/Users/bruce/homebrew/opt/llvm/lib/libclang.dylib': dlopen(/Users/bruce/homebrew/opt/llvm/lib/libclang.dylib, 0x0001): tried: '/Users/bruce/homebrew/opt/llvm/lib/libclang.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/Users/bruce/homebrew/Cellar/llvm/13.0.1_1/lib/libclang.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:12:43)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:23:12)
#2      initializeGlobals (package:ffigen/src/header_parser/data.dart:41:33)
#3      initParser (package:ffigen/src/header_parser/parser.dart:48:3)
#4      parse (package:ffigen/src/header_parser/parser.dart:22:3)
#5      main (package:ffigen/src/executables/ffigen.dart:54:19)
#6      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#7      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

I checked my Flutter environment:

❯ file /Users/bruce/dev_tools/flutter/bin/cache/dart-sdk/bin/dart
/Users/bruce/dev_tools/flutter/bin/cache/dart-sdk/bin/dart: Mach-O 64-bit executable x86_64

When I run brew install llvm to install llvm, what I get is a library for arm64, which I think is causing the error:

❯ lipo -info /Users/bruce/homebrew/Cellar/llvm/13.0.1_1/lib/libclang.dylib
Non-fat file: /Users/bruce/homebrew/Cellar/llvm/13.0.1_1/lib/libclang.dylib is architecture: arm64

It seems that the Flutter SDK does not have a version for Apple Silicon, so how to solve this problem?

❯ flutter doctor -v
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.3 21E230 darwin-arm, locale
    zh-Hans-CN)
    • Flutter version 2.8.1 at /Users/bruce/dev_tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (4 months ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1
    • Pub download mirror http://10.141.64.130:8080

[✓] Android toolchain - develop for Android devices (Android SDK version
    32.1.0-rc1)
    • Android SDK at /Users/bruce/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

I tried installing the Dart SDK for the Arm platform, but it still didn't work, using the standalone Dart environment, I get the following error:

❯ /Users/bruce/dev_tools/dart/bin/dart run ffigen
The Flutter SDK is not available.
#0      BoundSdkSource.getDirectory (package:pub/src/source/sdk.dart:125:7)
#1      SystemCache.load (package:pub/src/system_cache.dart:113:52)
#2      Entrypoint._assertLockFileUpToDate (package:pub/src/entrypoint.dart:599:19)
#3      Entrypoint.assertUpToDate (package:pub/src/entrypoint.dart:525:7)
#4      getExecutableForCommand (package:pub/src/executable.dart:304:16)
#5      RunCommand.run (package:dartdev/src/commands/run.dart:232:32)
#6      CommandRunner.runCommand (package:args/command_runner.dart:209:27)
#7      DartdevRunner.runCommand (package:dartdev/dartdev.dart:232:30)
#8      CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:119:25)
#9      new Future.sync (dart:async/future.dart:296:31)
#10     CommandRunner.run (package:args/command_runner.dart:119:14)
#11     runDartdev (package:dartdev/dartdev.dart:67:29)
#12     main (file:///opt/s/w/ir/cache/builder/sdk/pkg/dartdev/bin/dartdev.dart:11:9)
#13     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:293:32)
#14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
Scoundrelly answered 15/4, 2022 at 8:59 Comment(5)
How old is your Flutter version? Try flutter doctor -v and update questionDub
To run ffigen you just need the Dart SDK, so consider grabbing 2.16 Arm from here (dart.dev/get-dart/archive) and installing it in a separate folder.Dub
@RichardHeap I updated the problem description, it seems that ffigen cannot be executed using the standalone Dart environment.Scoundrelly
It should definitely work without Flutter - just tested it: D:\source\ffixyz>dart run ffigen --config config.yaml with D:\source\ffixyz>dart --version => Dart SDK version: 2.16.1 (stable)Dub
same question for almost all the python package, why Apple did not test anything?Sinclare
P
45

Running on M1 mac, these two commands solved my problem.

$ arch -arm64 brew install llvm

$ sudo gem install ffi
Payne answered 4/10, 2022 at 20:55 Comment(5)
🙏 Thank you sudo gem install ffi and reinstalling pods worked for me.Lochia
For some reason my mac m1 is noticeably slower after running these commands. Opening a new iterm terminal went from instant to 30 second+Glasgo
Its not working for me. I tried both commands but still having same issueBelfry
Same for me, tried both the command but still not working.Cygnet
For those who is using RVM, just do gem install ffi without sudo. (uninstall the previous install by doing gem uninstall ffi before doing so).Tranship
H
7

Here is the steps that worked for me,

  1. Install llvm with homebrew x86_64 version arch -x86_64 /usr/local/homebrew/bin/brew install llvm

  2. Install ffi for x86-64 version sudo arch -x86_64 gem install ffi

  3. Delete the pods directory and Podfile in iOS directory

  4. Invalidate cache and restart android studio

Healthy answered 13/9, 2022 at 14:38 Comment(1)
I don't know why there are no upvotes here, this actually worked for me and made total sense. Thanks Sanjay IshwarFalchion
A
5

I had passed thought this and it's awful! The problem here is how you installed LLVM, the LLVM itself installed via Home-brew by default as ARM64, but you should had installed the X86_64 version of it. To solve try this:

  1. Uninstall current LLVM: brew uninstall llvm ss
  2. Make sure to have a x86_64 of homebrew installed as showed in this medium article
  3. Then install with homebrew x86 version: arch -x86_64 /usr/local/homebrew/bin/brew install llvm

Then you ffi gen will work.

Accepted answered 19/4, 2022 at 12:45 Comment(0)
I
5

This error appears on MacBooks with an Apple Silicon M1 chip. The problem appears only when running a command thru Terminal configured to be opened with Rosetta.

What I did as a workaround was to:

  1. Clone Terminal application
  2. Rename it to "Terminal x86_64"
  3. Got info by right click + "Get info"
  4. Unchecked "Open with Rosetta"

So, every time I want to run a command that causes this error, I use the "Terminal x86_64" to run it and guess what? It works.

Intendant answered 2/7, 2022 at 6:22 Comment(1)
It still occurs, whether Terminal has the option "open with rosetta" checked or unchecked.Ryanryann
C
2

I encountered the same problem in VS Code, and I tried below instructions, then it worked.

  1. open the workspace setting in JSON format and add.
"terminal.integrated.profiles.osx": { "x86 bash": { "path": "/usr/bin/arch",
"args": [ "-arch", "x86_64", "/bin/bash" ] } },
"terminal.integrated.defaultProfile.osx": "x86 bash"

Here is the above code image.

code

  1. then open workspace setting in UI type defualt profile in search area than select workspace→terminal then select X86 bash

settings

Chimera answered 26/12, 2022 at 7:26 Comment(0)
T
1

I got this same import error with uamqp library

ImportError: dlopen(/Users/maheshwaran/Documents/newenv/lib/python3.10/site-packages/uamqp/c_uamqp.cpython-310-darwin.so, 0x0002): tried: '/Users/maheshwaran/Documents/newenv/lib/python3.10/site-packages/uamqp/c_uamqp.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

I resolved this import error by running below command:

  1. Uninstalling uamqp library:

    pip uninstall uamqp

  2. Setting ARCHFLAGS for arm64 architecture and using no cache so it will download respective library suits arm64 architecture.

    ARCHFLAGS="-arch arm64" pip install uamqp --compile --no-cache-dir

Hope this helps you as well !!

Turnbow answered 5/12, 2022 at 12:35 Comment(1)
Perhaps a universal binary ARCHFLAGS="-arch arm64 -arch arm64e -arch x86_64" is also an option.Collis
W
1

ReInstall Cocoapods from Homebrew (https://formulae.brew.sh/formula/cocoapods#default) :

brew install cocoapods

You may need to reinstall Homebrew first

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

this is from their homepage

Waterer answered 20/12, 2022 at 13:13 Comment(0)
S
0

Thanks to Richard Heap's suggestion, I've solved the problem!

As a Flutter project, you can't execute the dart command directly to the project directory, because some cache already exists after executing flutter pub get. Clear the package cache first, then execute dart pub get, and it works.

Scoundrelly answered 19/4, 2022 at 14:7 Comment(0)
H
0

I had the same problem. When I downloaded PyCharm, I didn't notice that the Mac version actually has two versions listed, the Intel version and the Apple Silicon version. The website defaulted to the Intel version (pycharm-professional-2022.3.2.dmg). I went back to the site and downloaded the Apple Silicon Version (pycharm-professional-2022.3.2-aarch64.dmg), remove the one I had installed and installed the new version. That fixed my problem. I hope this works for you.

Home answered 28/2, 2023 at 21:57 Comment(0)
N
0

If you are on Mac M1 and you upgraded your node version.

Delete the node modules and .lock file of you application and re-run npm install or yarn

Noleta answered 21/5 at 19:44 Comment(0)
C
-1

If you see this issue with the Nokogiri gem in Rails, remove

nokogiri (1.13.6-arm64-darwin)
      racc (~> 1.4)

from your Gemfile.lock and do a bundle install.

Cuckoo answered 21/6, 2022 at 0:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.