Cabal fails to build OpenGLRaw when installing library "ghc: could not execute: opt"

Viewed 197

I am trying to compile a Haskell program using Cabal which uses the library gloss, which requires OpenGL.

This fails when Cabal tries to build OpenGLRaw:

...
Starting     OpenGLRaw-3.3.4.0 (lib)
Building     OpenGLRaw-3.3.4.0 (lib)

Failed to build OpenGLRaw-3.3.4.0.
Build log ( /Users/rohan/.cabal/logs/ghc-8.10.7/OpnGLRw-3.3.4.0-5b38767b.log):
Configuring library for OpenGLRaw-3.3.4.0..
Preprocessing library for OpenGLRaw-3.3.4.0..
Building library for OpenGLRaw-3.3.4.0..
[  1 of 617] Compiling Graphics.GL.Groups ( src/Graphics/GL/Groups.hs,dist/build/Graphics/GL/Groups.o,dist/build/Graphics/GL/Group.dyn_o )
[  2 of 617] Compiling Graphics.GL.Types ( src/Graphics/GL/Types.hs,dist/build/Graphics/GL/Types.o,dist/build/Graphics/GL/Types.dyn_o )
...
[560 of 617] Compiling Graphics.GL.APPLE.FlushBufferRange (src/Graphics/GL/APPLE/FlushBufferRange.hs, dist/build/Graphics/GL/APPLE/FlushBufferRange.o, dist/build/Graphics/GL/APPLE/FlushBufferRange.dyn_o )
[561 of 617] Compiling Graphics.GL.APPLE.Fence ( src/Graphics/GL/APPLE/Fence.hs, dist/build/Graphics/GL/APPLE/Fence.o, dist/build/Graphics/GL/APPLE/Fence.dyn_o )
ghc: could not execute: opt
cabal: Failed to build OpenGLRaw-3.3.4.0 (which is required by exe:lsystems from lsystems-0.1.0.0). See the build log above for details.

After a bit of digging around SO it seems the issue is likely with the opt command from llvm (for example see this question and this question). However, I have llvm installed and its commands are on my path. The following line:

export PATH="/opt/homebrew/Cellar/llvm/12.0.1/bin:$PATH"

is in the .zshrc file and running the command opt --version works fine. I also tried adding these environment variables:

export CPLUS_INCLUDE_PATH=$(llvm-config --includedir):$CPLUS_INCLUDE_PATH
export LD_LIBRARY_PATH=$(llvm-config --libdir):$LD_LIBRARY_PATH 

as this this question suggested, but that didn't work either.

Other possibly relevant information:

  • I am using macOS Big Sur 11.5, on an ARM Mac.
  • cabal, ghc, and llvm are installed with Homebrew
  • Using cabal 3.4.0.0, ghc 8.10.7, and opt 12.0.1
  • This process can fail at different steps. For example the build above failed at [561 of 617] but when I tried it just now it failed at [540 of 617].
0 Answers
Related