ghc - Can't compile haskell project: linking step fails

ID : 274320

viewed : 71

Tags : haskellghccabalosx-maverickshaskell

Top 4 Answer for ghc - Can't compile haskell project: linking step fails

vote vote


Here's what finally fixed it. My cabal config was something like this:

library   exposed-modules:       My.Module1     , My.Module3   executable my-executable   main-is:             Main.hs   build-depends:       base >=4.6 && <4.7     , chorez 

Main.hs for the executable imports My.Module3. My.Module3 imports the private My.Module2. Including My.Module2 under exposed-modules fixed the issue. I figured this out because I realized that all the symbols that couldn't be found came from that module. cabal repl worked just fine (I tested the modules by hand and they all basically worked), but cabal run didn't. I feel like I should be able to use a library with private modules in an executable, but in this case I just forgot to add the new module to the list, and I have no reason to make any module private, so I'm up and running for now.

vote vote


A bit late to the party, but what you want is to put your non-exposed modules in the other-modules section.

From the Cabal User Guide:

Modules included in the package

For a library, cabal init looks in the project directory for files that look like Haskell modules and adds all the modules to the exposed-modules field. For modules that do not form part of your package’s public interface, you can move those modules to the other-modules field. Either way, all modules in the library need to be listed.

vote vote


Uninstall and reinstall - not GHC, but Xcode. That resolved the issue for me.

vote vote


Top 3 video Explaining ghc - Can't compile haskell project: linking step fails