0

So I have the following makefile which I want to use to compile my haskell program. However, in my program.hs file I have imported a library that is not in the standard Haskell distribution (e.g. Data.List). As a result, when I try to compile I get the error below. How can I include the said library so that it compiles fine? P.S. I am NOT interested in other approaches which do not involve a makefile, thank you.

error:

Linking program...
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

makefile:

 program: program.hs
        ghc --make -static -optl-static program.hs
Sreten Jocić
  • 165
  • 1
  • 14
  • 1
    Please post a [mcve] (this includes the .hs file). – n. m. could be an AI Mar 14 '18 at 16:59
  • `crt0` is a C library, not a Haskell one. Something is going wrong, and it does not depend on Haskell libraries. I wonder if your `clang` can produce static executables from C sources (?) – chi Mar 14 '18 at 17:45
  • @chi thx for the answer, I dont know anything about c, but I was getting `gcc failed in phase Linker. (Exit code: 1) makefile:2: recipe for target 'program' failed make: ***[program] Error 1` without the 2 static options and adding them fixed it – Sreten Jocić Mar 14 '18 at 17:55
  • 3
    As you seem to have anticipated, the reasonable answer is: _don't use `make` to build Haskell projects, use `cabal` or `stack` instead_. Make, especially GNU Make, is bogged down not only with anachronistic environment assumptions but also ridiculous implicit rules for languages nobody has been using for 30 years anymore. (Well, not literally _nobody_, and of course you can and should just turn those off, but still...) If it matters because you don't have root permissions and only GHC installed, note that `stack` can be installed entirely in user space. – leftaroundabout Mar 14 '18 at 19:25
  • @leftaroundabout Of course `cabal` can be installed entirely in user space, too (and that is the default behavior of `bootstrap.sh`). – Daniel Wagner Mar 14 '18 at 22:40

1 Answers1

0

You went down the wrong path with static options. I assume you're on os-x. As explained at ld: library not found for -lcrt0.o on OSX 10.6 with gcc/clang -static flag that just makes things worse. In fact you got a different error, because you got an earlier error.

To write a good makefile, first ensure you can run ghc to compile the program without make, just by running the commands in the shell.

I.e. try to compile just ghc --make program.hs and see what happens. If you have the other libraries in your package environment already, it doesn't matter if they're in the standard distribution or not.

sclv
  • 38,665
  • 7
  • 99
  • 204