1

I have these two modules:

module Server where
import Data.JSON.Schema.Generic (gSchema)
import Data.JSON.Schema.Types (JSONSchema(schema))
import Two
instance JSONSchema Data where 
    schema = gSchema
main :: IO ()
main = undefined

{-# LANGUAGE DeriveGeneric #-}
module Two where
import GHC.Generics (Generic)
data Data = Data {
    scName :: String
} deriving Generic

When trying to build the project containing these two files, the ghc in linking phase throws several errors looking like this: (They only differ in the (.data+0XXXX) part).

dist/dist-sandbox-190abc84/build/libHSserver-0.1.a(Server.o):(.data+0x1b8): undefined reference to `serverzm0zi1_Two_zdfGenericData_closure'

And final message is:

collect2: error: ld returned 1 exit status

I tried this with ghc 7.8.3 and 7.6.3 and they both behave similarly.

I can make this functionality work if put all the code into one module.

Can anyone explain, what's happening here, please?

ryskajakub
  • 6,351
  • 8
  • 45
  • 75

1 Answers1

2

I'm using GHC 7.8.3 (from the Haskell Platform). Below is a cabal.config file with the specific versions used in the sandbox.

constraints: aeson ==0.8.0.2,
             array ==0.5.0.0,
             attoparsec ==0.12.1.2,
             base ==4.7.0.1,
             bytestring ==0.10.4.0,
             containers ==0.5.5.1,
             deepseq ==1.3.0.2,
             dlist ==0.7.1,
             generic ==0.1.0.0,
             generic-aeson ==0.2.0.2,
             generic-deriving ==1.7.0,
             ghc-prim ==0.3.1.0,
             hashable ==1.2.2.0,
             integer-gmp ==0.5.1.0,
             json-schema ==0.7.1.1,
             mtl ==2.1.3.1,
             old-locale ==1.0.0.6,
             pretty ==1.1.1.1,
             primitive ==0.5.2.1,
             rts ==1.0,
             scientific ==0.3.3.2,
             syb ==0.4.1,
             tagged ==0.7.3,
             template-haskell ==2.9.0.0,
             text ==1.1.1.3,
             time ==1.4.2,
             transformers ==0.3.0.0,
             unordered-containers ==0.2.5.1,
             vector ==0.10.9.1
ErikR
  • 51,541
  • 9
  • 73
  • 124
  • Ok, that works, but still it doesn't resolve my problem. I have some other dependencies in the project, so I didn't wont dump all of them here and just boil the problem to the essence. But i didn't suceed :-/ – ryskajakub Nov 28 '14 at 21:05
  • Hopefully you've figured it out. You shouldn't have to pin the versions if you install in a sandbox. Perhaps there was a bad .o file lying around from a previous compile? Anyway, feel free to get in touch if you are still having problems. – ErikR Nov 28 '14 at 21:31
  • just for your information, the problem was, that I used the module with this two files as a library for another cabal executable, and the library didn't expose the `Two` module – ryskajakub Nov 29 '14 at 19:38