Alcides Fonseca

40.197958, -8.408312

FFI troubleshoot in Haskell

When installing Haskell’s HLint via:

stack install hlint

I was getting the following error:


base-compat-batteries            > [  2 of 118] Compiling Control.Concurrent.Compat.Repl.Batteries                                          
hashable                         >                                                                                                          
hashable                         > /private/var/folders/3g/7tpj8zwx14qddcr3bt_w8jnr0000gn/T/stack-e594623fe9dbdb84/hashable-1.3.5.0/In file included from /var/folders/3g/7tpj8zwx14qddcr3bt_w8jnr0000gn/T/ghc52550_0/ghc_20.c:4:0: error:
hashable                         >                                                                                                          
hashable                         >                                                                                                          
hashable                         > In file included from /Users/alcides/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffi.h:66:0: error:
hashable                         >                                                                                                          
hashable                         >                                                                                                          
hashable                         > /Users/alcides/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffitarget.h:6:10: error:
hashable                         >      fatal error: 'ffitarget_arm64.h' file not found                                                     
hashable                         >   |                                                                                                      
hashable                         > 6 | #include "ffitarget_arm64.h"                                                                         
hashable                         >   |          ^                                                                                           
hashable                         > #include "ffitarget_arm64.h"                                                                             
hashable                         >          ^~~~~~~~~~~~~~~~~~~                                                                             
hashable                         > 1 error generated.                                                                                       
hashable                         > `gcc' failed in phase `C Compiler'. (Exit code: 1)   

The problem is that my clang was installed via home-brew. As such, there were a few missing paths. The solution was to run the following to find the location of this header:

find / -iname ffitarget_arm64.h

My output was:

find: /usr/sbin/authserver: Permission denied
find: /Library/Application Support/Apple/Screen Sharing/Keys: Permission denied
find: /Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /Library/Application Support/Apple/AssetCache/Data: Permission denied
find: /Library/Application Support/Apple/Remote Desktop/Task Server: Permission denied
find: /Library/Application Support/Apple/Remote Desktop/Client: Permission denied
find: /Library/Application Support/ApplePushService: Permission denied
find: /Library/Application Support/com.expressvpn.ExpressVPN/data: Permission denied
/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/ffi/ffitarget_arm64.h
/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/include/ffi/ffitarget_arm64.h
...

Now you need to pick the first one (second to last line in the previous output) as copy the path up to include (inclusive). Now use it in the following line, or add it to your ~/.zshrc.

C_INCLUDE_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include/