Skip to content

cffi cannot be built correctly on macOS if libffi is installed in /usr/local #297

Done

Description

@thisisgk

macOS: 10.13.6
cffi: 2.1.1
libffi: 3.8.1
python: 3.15.2

When using a python application (in my case, mitmproxy), this error occurs:
ffi_prep_closure(): bad user_data (it seems that the version of the libffi library seen at runtime is different from the 'ffi.h' file seen at compile-time)

It appears that if libffi is installed in /usr/local, cffi gets built using system /usr/include/ffi and pkg-config /usr/local/lib.

setup.py retrieves /usr/local/include and /usr/local/lib from pkg-config, and it sets -iwithsysroot/usr/include/ffi for macOS.
Checking the verbose output of compilation, clang ignores the passed /usr/local/include, so it reads ffi.h from /usr/include/ffi:

ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 /private/tmp/build-env-xgzeuiks/include
 /Library/Frameworks/Python.framework/Versions/3.15/include/python3.15
 /usr/include/ffi
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/10.0.0/include
 /Library/Developer/CommandLineTools/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

Activity

  1. mattip commented on Dec 4, 2026

    @mattip
    Contributor

    Can you check that #298 fixes the problem?

  2. thisisgk commented on Dec 4, 2026

    @thisisgk
    Author

    Thank you. It worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions