moocfi / haskell-mooc

Haskell MOOC University of Helsinki
Other
307 stars 414 forks source link

Encountered an error related to ffi.h while building the project on Apple Silicon macOS Ventura 13.3.1 #83

Closed 0407-zh closed 1 year ago

0407-zh commented 1 year ago

While attempting to execute the stack build command to build the project on an Apple Silicon macOS system, I encountered the following issue:

primitive           > /private/var/folders/w6/wcmb44552qq33sxlxwhptwqm0000gn/T/stack-6a68bccd28c38a9e/primitive-0.7.3.0//var/folders/w6/wcmb44552qq33sxlxwhptwqm0000gn/T/ghc66884_0/ghc_45.c:4:10: error:
primitive           >      fatal error: 'ffi.h' file not found
primitive           >   |
primitive           > 4 | #include <ffi.h>
primitive           >   |          ^
primitive           > #include <ffi.h>
primitive           >          ^~~~~~~
primitive           > 1 error generated.
primitive           > `gcc' failed in phase `C Compiler'. (Exit code: 1)

The issue of the missing libffi library occurs in multiple places.

Error: [S-7282]
       Stack failed to execute the build plan.

       While executing the build plan, Stack encountered the following errors:

       [S-7011]
       While building package primitive-0.7.3.0 (scroll up to its section to see the
       error) using:
       /Users/chenjunqi/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.7 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

       [S-7011]
       While building package old-time-1.1.0.3 (scroll up to its section to see the
       error) using:
       /private/var/folders/w6/wcmb44552qq33sxlxwhptwqm0000gn/T/stack-6a68bccd28c38a9e/old-time-1.1.0.3/.stack-work/dist/aarch64-osx/Cabal-3.6.3.0/setup/setup --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

       [S-7011]
       While building package network-3.1.2.8 (scroll up to its section to see the
       error) using:
       /private/var/folders/w6/wcmb44552qq33sxlxwhptwqm0000gn/T/stack-6a68bccd28c38a9e/network-3.1.2.8/.stack-work/dist/aarch64-osx/Cabal-3.6.3.0/setup/setup --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

       [S-7011]
       While building package hourglass-0.2.12 (scroll up to its section to see the
       error) using:
       /Users/chenjunqi/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.7 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

       [S-7011]
       While building package basement-0.0.15 (scroll up to its section to see the
       error) using:
       /Users/chenjunqi/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.7 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

       [S-7011]
       While building package direct-sqlite-2.3.28 (scroll up to its section to see
       the error) using:
       /Users/chenjunqi/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.7 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

       [S-7011]
       While building package hashable-1.4.2.0 (scroll up to its section to see the
       error) using:
       /Users/chenjunqi/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.7 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

       [S-7011]
       While building package clock-0.8.3 (scroll up to its section to see the error)
       using:
       /Users/chenjunqi/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.7 --verbose=1 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.6.3.0 build --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1 

This issue is caused by the missing libffi library. libffi is a cross-platform foreign function interface library used for calling functions compiled to native code.

I have installed libffi on macOS using Homebrew and added the include directory of libffi to the project's stack.yaml file, but I still encountered the same issue. How can I resolve this problem?

Thank you!

opqdonut commented 1 year ago

Thanks for reporting that, but I'm not a macOS user so I have no idea how to get the right libffi installed. I wonder if installing Stack using https://www.haskell.org/ghcup/ might work more reliably?

0407-zh commented 1 year ago

I found a solution. Diagnosed and fixed with help from the ghcup devs here: https://github.com/haskell/ghcup-hs/issues/814

The problem was that I had not re-installed Xcode command line tools after a recent macOS or Xcode software update.

This was fixed by installing the command line tools: xcode-select --install

This ensured that the expected symlink was in place at /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

stack build was then able to succeed.