Deriving Generic from data declared in another file fails

101 views Asked by At

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?

1

There are 1 answers

3
ErikR On BEST ANSWER

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