Skip to content

Cabal fails to link Paths module to executables in separate directories #1759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hanshoglund opened this issue Apr 8, 2014 · 1 comment
Closed

Comments

@hanshoglund
Copy link
Contributor

In a library+executable package, executables that do not share their source directories with the library sources should be able to refer to exports from the library (as per #81). However the following setup fails to link.

(This repository provides a full project demonstrating the issue, see below for a summary).

Cabal file

library
    build-depends: base >= 4 && < 5
    hs-source-dirs: src
    default-language: Haskell2010
    exposed-modules: FooBar

executable "test-foo-bar"
    build-depends: foo-bar, base >= 4 && < 5
    hs-source-dirs: tools
    default-language: Haskell2010
    main-is: test-foo-bar.hs

Sources

-- src/FooBar.hs
module FooBar where
import Paths_foo_bar (version)
import Data.Version
versionString = showVersion version
-- tools/test-foo-bar.hs
module Main where
import FooBar (versionString)
main = putStrLn $ "The version is " ++ versionString

Output

$ cabal build
[1 of 1] Compiling Main             ( tools/test-foo-bar.hs, dist/build/test-foo-bar/test-foo-bar-tmp/Main.o )
Linking dist/build/test-foo-bar/test-foo-bar ...
Undefined symbols for architecture x86_64:
  "_foozmbarzm0zi2_Pathszufoozubar_version1_closure", referenced from:
      _foozmbarzm0zi2_FooBar_versionString_info in libHSfoo-bar-0.2.a(FooBar.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
@hanshoglund hanshoglund changed the title Fails to link Paths module from binaries in separate directory Cabal fails to link Paths module from binaries in separate directory Apr 8, 2014
@hanshoglund hanshoglund changed the title Cabal fails to link Paths module from binaries in separate directory Cabal fails to link Paths module to executables in separate directory Apr 8, 2014
@hanshoglund hanshoglund changed the title Cabal fails to link Paths module to executables in separate directory Cabal fails to link Paths module to executables in separate directories Apr 8, 2014
hanshoglund added a commit to music-suite/music-preludes that referenced this issue Apr 9, 2014
@ingemaradahl
Copy link

You need to make sure to expose the generated Paths_ module. Add

other-modules:      Paths_foo_bar

to your library section in foo-bar.cabal, and it should link fine. Not a very nice message from GHC though :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants