ocaml-ctypes
ocaml-ctypes copied to clipboard
opam installation fails on macos 12.6.3: libffi.h
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
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!?!
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.
opam pin
ning ctypes to the local copy succeeds in installing ctypes. the problem appears to be with the version on opam.
I face the same issue
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
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
.
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.
I reinstalled pkg-config with
brew reinstall pkg-config
.
so the issue is with brew-installed pkg-config then?
I reinstalled pkg-config with
brew reinstall pkg-config
.so the issue is with brew-installed pkg-config then?
Yes, it looks like.
brew reinstall pkg-config
appears to have fixed the problem for me too
hmm. now i'm getting the same error again, even after brew reinstall pkg-config
. this is after an upgrade to ventura.
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
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
.