使用Cabal构建Haskell可执行文件时出现未定义的引用和gcc错误?

时间:2019-05-08 05:11:26

标签: haskell cabal nix cabal-install

我建立了一个简单的cabal项目,以尝试更好地熟悉它,并且我有一个非常简单的Main.hs文件:

main :: IO ()
main = putStrLn "Hello, World!"

因此,我尝试使用cabal new-configure然后使用cabal new-build来构建它。 configure命令没有问题,但是构建它可以做到这一点:

[1 of 1] Compiling Main             ( Main.hs, /home/redacted/Documents/Haskell/nixtut/dist-newstyle/build/x86_64-linux/ghc-8.0.1/newp-0.1.0.0/x/newp/build/newp/newp-tmp/Main.o )
Linking /home/daniel/Documents/Haskell/nixtut/dist-newstyle/build/x86_64-linux/ghc-8.0.1/newp-0.1.0.0/x/newp/build/newp/newp ...
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `_IO_enable_locks@GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__mmap@GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__munmap@GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__mprotect@GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__tunable_get_val@GLIBC_PRIVATE'
/nix/store/6yjpyqkx6d9k5f2s2g8h9kz40q6rz1yx-binutils-2.31.1/bin/ld: //nix/store/siks2gcfwx6qwh27m7c5r5lixcr621bd-glibc-2.27/lib/libpthread.so.0: undefined reference to `__sigtimedwait@GLIBC_PRIVATE'
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)

这是我的.cabal文件:

name:                newp
version:             0.1.0.0
synopsis:            toying around
-- description:
homepage:            none
-- bug-reports:
license:             BSD-3-Clause
license-file:        LICENSE
author:              redacted
maintainer:          none
-- copyright:
category:            practice
extra-source-files:  CHANGELOG.md

executable newp
  main-is:             Main.hs
  --other-modules:
  -- other-extensions:
  build-depends:       base ^>=4.9.0.0
  -- hs-source-dirs:
  default-language:    Haskell2010

我似乎不明白怎么了。已经安装了GCC,我没有尝试链接任何外部库,没有使用任何其他模块,我也不知道这些引用所指的是什么。

感谢您的帮助,因为坦率地说,我不知道从哪里开始。我尝试过在线查找,但所有情况都不尽相同,解决方案似乎不适用于我。我注意到,对于其他人,当在cabal文件中链接或不包含模块存在问题时,也会发生类似的错误,但是我不确定这在这里如何或是否适用。

1 个答案:

答案 0 :(得分:1)

虽然对于为什么会出现错误我没有明确的答案,但是在重新安装nix之后,我终于可以构建项目了。因此问题不在于阴谋集团。