【问题标题】:Undefined references and gcc error when building Haskell executable with cabal?使用 cabal 构建 Haskell 可执行文件时未定义的引用和 gcc 错误?
【发布时间】:2019-05-08 05:11:25
【问题描述】:

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

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

然后我尝试构建它,使用cabal new-configure,然后使用cabal new-build。配置命令没有问题,但是构建它会给出:

[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 文件中存在链接或不包含模块的问题时,会发生类似的错误,但我不确定这如何或是否适用于此。

【问题讨论】:

  • 您是否尝试查看cabal new-build -v 是否提供了更多信息?
  • 这看起来像是您的 Nix 构建环境的安装问题; ghc --make Main.hs 有效吗?
  • @hvr ghc 可以编译,但你可能是对的,这是 nix 安装的问题。重新安装 nix 后,项目可以构建

标签: haskell cabal nix cabal-install


【解决方案1】:

虽然我对错误发生的原因没有明确的答案,但在重新安装 nix 后,我终于可以构建项目了。所以问题不在于阴谋集团。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多