使用 cabal 构建 Haskell 可执行文件时出现未定义引用和 gcc 错误?
Undefined references and gcc error when building Haskell executable with cabal?
我建立了一个简单的 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 已安装,我没有尝试 link 任何外部库,我没有使用任何其他模块,我不知道这些引用暗示了什么。
感谢任何帮助,因为坦率地说,我不知道从哪里开始。我试过在线查看,但所有情况都不同,解决方案似乎并不适用于我。我注意到对于其他人来说,当 linking 出现问题或不在 cabal 文件中包含模块时,也会出现类似的错误,但我不确定这里如何或是否适用。
虽然对于错误发生的原因我没有明确的答案,但在重新安装 nix 后我终于可以构建项目了。所以问题不在于阴谋集团。
我建立了一个简单的 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 已安装,我没有尝试 link 任何外部库,我没有使用任何其他模块,我不知道这些引用暗示了什么。
感谢任何帮助,因为坦率地说,我不知道从哪里开始。我试过在线查看,但所有情况都不同,解决方案似乎并不适用于我。我注意到对于其他人来说,当 linking 出现问题或不在 cabal 文件中包含模块时,也会出现类似的错误,但我不确定这里如何或是否适用。
虽然对于错误发生的原因我没有明确的答案,但在重新安装 nix 后我终于可以构建项目了。所以问题不在于阴谋集团。