ocaml-ctypes icon indicating copy to clipboard operation
ocaml-ctypes copied to clipboard

opam installation fails on macos 12.6.3: libffi.h

Open nilsbecker opened this issue 1 year ago • 13 comments

trying to install ctypes.0.20.1 on macos 12.6.3, in a new 4.14.1 switch. this fails with ffi.h not found, similar to a very old bug report which i decided not to revive. a homebrew installed libffi is present. ctypes-13982-caa0cb.out.txt ctypes-13982-caa0cb.env.txt ctypes-13982-caa0cb.info.txt

nilsbecker avatar Feb 10 '23 13:02 nilsbecker

the problem persists. going through the .out file above i find calls like

ocamlfind ocamlc -package integers -thread -package threads -principal -short-paths -strict-sequence -g -ccopt "-I/Users/nbecker/.opam/414torch/lib/integers" -thread -ccopt -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/ffi -c -o _build/src/ctypes-foreign/ctypes_closure_properties.cmo -I _build/src/ctypes-foreign -I _build/src/ctypes src/ctypes-foreign/ctypes_closure_properties.ml

this is nonsense: MacOSX10.14 is ancient, and the corresponding include directory does not exist on my machine!?!

nilsbecker avatar Feb 15 '23 08:02 nilsbecker

interestingly, git cloning this repository and building via make succeeds for me! during the build a file libffi.config is generated, which appears to be correct. it picks up the homebrew installed libffi.

libffi_available=true
libffi_opt=-I/usr/local/Cellar/libffi/3.4.4/include
libffi_lib=-L/usr/local/Cellar/libffi/3.4.4/lib -lffi

for some reason the opam install process did not do the same ?!

i had also tried opam clean to clear potential stale cache build artefacts to no avail.

nilsbecker avatar Feb 15 '23 16:02 nilsbecker

opam pinning ctypes to the local copy succeeds in installing ctypes. the problem appears to be with the version on opam.

nilsbecker avatar Feb 15 '23 16:02 nilsbecker

I face the same issue

dannywillems avatar Feb 21 '23 16:02 dannywillems

Updating to opam 2.1.4 did not fix the issue. Cleaning the opam cache too. The following commands work:

opam switch create ./ 4.14.1
opam install ctypes

Installing on 5.0.0 is fine too

dannywillems avatar Feb 21 '23 16:02 dannywillems

It seems it uses the output of pkg-config (see discover.ml). pkg-config libffi --cflags gives a wrong path.

I reinstalled pkg-config with brew reinstall pkg-config.

dannywillems avatar Feb 21 '23 16:02 dannywillems

And if you updated recently your MacOS version, don't forget to install the SDKs:

xcode-select --install

You should then have the correct SDK version installed in /Library/Developer/CommandLineTools/SDKs/ (for instance MacOSX13.sdk if you are using Ventura). pkg-config does not check if the SDK directory does exist. It only points to the SDK of your current MacOS version.

dannywillems avatar Feb 21 '23 16:02 dannywillems

I reinstalled pkg-config with brew reinstall pkg-config.

so the issue is with brew-installed pkg-config then?

nilsbecker avatar Feb 21 '23 16:02 nilsbecker

I reinstalled pkg-config with brew reinstall pkg-config.

so the issue is with brew-installed pkg-config then?

Yes, it looks like.

dannywillems avatar Feb 21 '23 16:02 dannywillems

brew reinstall pkg-config appears to have fixed the problem for me too

nilsbecker avatar Feb 21 '23 19:02 nilsbecker

hmm. now i'm getting the same error again, even after brew reinstall pkg-config. this is after an upgrade to ventura.

nilsbecker avatar Feb 27 '23 11:02 nilsbecker

ok, cleared up: the issue was that the ventura upgrade did not also upgrade the commandline tools. after installing these again as described above, pkg-config points to a libffi path that actually exists and ctypes installation succeeds

nilsbecker avatar Feb 27 '23 11:02 nilsbecker

I just had this problem. Reinstalling xcode-select --install and reinstalling pkg-config was not sufficient (but were possibly necessary). Inspecting the logs of opam install ctypes it seemed that it didn't even make any attempt to point at the location of ffi.h (no -I flag with the appropriate path).

In the end, the solution was pointed at in a separate Linux issue, in the error opam seems to emit on Linux in different circumstances: running export LIBFFI_CFLAGS=$(pkg-config libffi --ctypes) before opam install ctypes.

johanrosenkilde avatar Jun 26 '23 19:06 johanrosenkilde