15

I am trying to implement micropython on unix, which requires libffi-dev. I installed in this way brew install libffi-dev. But it seems that there is no libffi-dev can be found.

Is there any way to install libffi-dev on Mac os. Thank you.

Paul R
  • 208,748
  • 37
  • 389
  • 560
Xiufen Xu
  • 463
  • 3
  • 6
  • 11
  • 1
    Try `brew install libffi`. – Paul R Jun 22 '17 at 17:56
  • 1
    If this worked you should answer the question and accept it. – Victor 'Chris' Cabral Jun 22 '17 at 18:11
  • @PaulR Thank you Paul. `brew install libffi` works on Mac. But I am confused that are libffi and libffi-dev the same thing? – Xiufen Xu Jun 22 '17 at 18:37
  • 9
    @XiufenXu: on Linux they often separate packages into `xxx` and `xxx-dev`, where `xxx` contains the minimum you need just to use a library or whatever, while the `xxx-dev` package contains source code and other supporting files to enable you to modify and rebuild the package if needed. With Homebrew on Mac OS X you typically get all this in just one `xxx` package, so you won't normally see separate `xxx-dev` packages (although there are a few exceptions to this rule of thumb, e.g. `google-chrome` and `google-chrome-dev`). – Paul R Jun 22 '17 at 19:00
  • 1
    @PaulR That's really what I want to clear up. Thanks a lot. – Xiufen Xu Jun 22 '17 at 19:50

3 Answers3

35

On Mac OS X you just need:

$ brew install libffi
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 2
    Any alternative to brew, it tends to own my python whenever I use it which equals instant regret. – Paul Kenjora Sep 15 '20 at 17:03
  • @PaulKenjora: try MacPorts or even fink ? – Paul R Sep 15 '20 at 18:34
  • You can look at the source to figure out what it does. Go to https://formulae.brew.sh/formula/libffi and click "Formula code: libffi.rb on GitHub". We can see the dependencies via the `depends_on`: 1. autoconf 2. automake 3. libtool We can then convert it to the following: 1. git clone https://github.com/libffi/libffi.git 2. `cd libffi` 3 `./autogen.sh` 4. `./configure` 5. `make install` Homebrew shouldn't conflict with your Python, if it does you've probably installed Python via brew. You should probably be using venvs or something, it'll make your life much easier :-). – Josh Feb 24 '23 at 08:33
4

Error:

Library not loaded: /usr/local/opt/libffi/lib/libffi.7.dylib

The following worked (it’s not an ln -s but it did the trick):

sudo mkdir /usr/local/opt/libffi
sudo mkdir /usr/local/opt/libffi/lib
sudo cp /usr/lib/libffi.dylib /usr/local/opt/libffi/lib/libffi.7.dylib

Turns out Xcode already installs a library, it’s just not in the right spot.

Melebius
  • 6,183
  • 4
  • 39
  • 52
Paul Kenjora
  • 1,914
  • 18
  • 20
  • 3
    Symbolic links would probably be a better approach than copying. That way you get the correct version when you update the OS. – Paul R Sep 15 '20 at 20:17
0

This worked for me when paramiko python library was giving file not found error ::

ln -s /usr/local/opt/libffi/lib/libffi.dylib /usr/local/lib/libffi.7.dylib
PhoebeB
  • 8,434
  • 8
  • 57
  • 76