7

My question comes in two parts. The first is that when I compile my project I get a long list of errors of the form

  (.text+0x137f): undefined reference to `raytrzuAd6RComi0WmBiuT4685WWH_Types_zdfBinaryColor_closure'

The full list of errors can be found here The code that produces this error can be found here.

I am using ghc 7.10.1 and cabal 1.22.4.0.

The second part of my question is that despite following the same cabal structure as this question, cabal still recompiles the library 3 times each cabal build despite the executables and the library all having a unique hs-source-dir and depending on the library.

EDIT: as far as the triple compilation is concerned, the first time it builds .o files [ 2 of 15] Compiling Types ( src/Types.hs, dist/build/Types.o ). The second time it builds .p_o files [ 2 of 15] Compiling Types ( src/Types.hs, dist/build/Types.p_o ) which are caused by TemplateHaskell and profiling.

Community
  • 1
  • 1
Justin Raymond
  • 3,413
  • 2
  • 19
  • 28

1 Answers1

6

You should include all the other non-exported modules in your Cabal file in the other-modules field, otherwise they won't be linked in properly when producing the final library or executable.

You can see the Cabal User's Guide for more information (although that pretty much sums up the situation with other-modules!).

Antal Spector-Zabusky
  • 36,191
  • 7
  • 77
  • 140
  • First of all, sorry for posting this into a comment, but I ran into a similar situation as the questioner. I'm using an external library called **gstreamer** for the haskell package **haskell-gi**. Now the linker runs into several **undefined reference**' problems. Example: **"undefined reference to `g_irepository_require'"** . This method is part of a .c or .h file, that is called gi-repository.c / gi-repository.h. I have looked through Cabals' User Guide but still don't have a clue how to add that file to **"other-modules"**. Could you give me an example? – oRole Sep 30 '17 at 16:21
  • @oRole: Since that's a C function, you handle it differently – this answer deals specifically with Haskell code. I don't have a quick answer, so you should [ask a new question!](https://stackoverflow.com/questions/ask) :-) – Antal Spector-Zabusky Oct 01 '17 at 02:33
  • Thank you anyways! – oRole Oct 01 '17 at 08:27