Ricky Pang
Ricky Pang

Reputation: 131

Unable to install magic-1.1 for iHaskell

Main Issue

I am new to Haskell and I wanna use iHaskell, an interactive Haskell similar to Jupyter notebook in Python. I noticed that the magic library is missing after running stack install --fast . Therefore, I run stack install magic-1.1 --extra-include-dirs {$HOMEBREW_PREFIX}/include --extra-lib-dirs {$HOMEBREW_PREFIX}/lib on the fish shell in my M1 Max MacBook. However, the error still occurred as follow

stack install magic-1.1 --extra-include-dirs {$HOMEBREW_PREFIX}/include --extra-lib-dirs {$HOMEBREW_PREFIX}/lib
magic> configure
magic> Warning: magic.cabal:27:28: version operators used. To use version operators
magic> the package needs to specify at least 'cabal-version: >= 1.8'.
magic> Configuring magic-1.1...
magic> Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.7: Missing dependency on a foreign
magic> library:
magic> * Missing (or bad) C library: magic
magic> This problem can usually be solved by installing the system package that
magic> provides this library (you may need the "-dev" version). If the library is
magic> already installed but in a non-standard location then you can use the flags
magic> --extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
magic> library file does exist, it may contain errors that are caught by the C
magic> compiler at the preprocessing stage. In this case you can re-run configure
magic> with the verbosity flag -v3 to see the error messages.
magic>

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 magic-1.1 (scroll up to its section to see the error) using:
       [A long string of dir here and I do not shown here for neatness  ]
       Process exited with code: ExitFailure 1

How can I fix this error?

Installation Detail and Similar Case

I installed ghcup using home-brew and then installed Stack, HLS, cabal, GHC using ghcup tui. I find a similar discussion on reddit. The problem may be that the pkg-config cannot see libmagic though I installed them using homebrew.

Upvotes: 0

Views: 440

Answers (2)

Charbel
Charbel

Reputation: 1

I had similar issue resolved after installing modular with the following command.

curl -sSL https://get.modular.com | sh

And after that I have installed magic.

curl -ssL https://magic.modular.com/7bba6c72-9d06-414c-a815-05f327c7a19g | bash

Following commands worked perfectly.

magic init my-project
cd my-project
magic add "python==3.11"
magic add max

Upvotes: 0

Ricky Pang
Ricky Pang

Reputation: 131

Solution

After struggling for a few hours, I found that the solution was to add path variables in the stack install --fast. For Apple Silicon and HomeBrew users, the brew directory locates at /opt/homebrew/ and for stack to see pkg-config or libmagic, we need to add additional flags into the stack install command. This instruction was clearly stated on the Github page --extra-include-dirs ${HOMEBREW_PREFIX}/include --extra-lib-dirs ${HOMEBREW_PREFIX}/lib but I did not change the variable name ${HOMEBREW_PREFIX}. After changing it back to /opt/homebrew to works fine.

Upvotes: 1

Related Questions