可执行文件的堆栈链接在一个实例中失败,在另一个实例中完成 - 为什么?

Stack linking of executable fails in one instance, completes another - why?

很抱歉问了一个有点复杂的问题,但是 link 使用堆栈执行可执行文件在一个实例中莫名其妙地失败了,但在另一个实例中却没有。

这是我的项目:

$ cat stack.yaml 
extra-package-dbs: []
packages:
- umecore-hs
- fontrans-tools
extra-deps:
- parsec3-1.0.1.8
- parsec3-numbers-0.1.0
resolver: lts-5.15
flags:
      parsec3-numbers:
        parsec3: true

这里正在构建两个可执行文件,每个包中一个。 第一个包 umecore-hs 的 cabal 文件的可执行部分如下所示:

Executable umequery
  Main-Is:        umequery.hs
  Hs-Source-Dirs: src
  default-language:    Haskell2010
  build-depends:       base,  parsec3, filepath,  time,  bytestring, unix, cryptohash, optparse-applicative, text, base16-bytestring, utf8-string, transformers, regex-pcre, regex-base, direct-sqlite, text , parsec3-numbers

这在我的 OS X 10.11.5 机器上构建良好:

$ rm -Rf .stack-work/
$ stack build umecore-hs
parsec3-1.0.1.8: configure
parsec3-1.0.1.8: build
parsec3-1.0.1.8: copy/register
parsec3-numbers-0.1.0: configure
parsec3-numbers-0.1.0: build
parsec3-numbers-0.1.0: copy/register
umecore-hs-0.0.1.0: configure
Configuring umecore-hs-0.0.1.0...
umecore-hs-0.0.1.0: build
Preprocessing library umecore-hs-0.0.1.0...
In-place registering umecore-hs-0.0.1.0...
Preprocessing executable 'umequery' for umecore-hs-0.0.1.0...
Linking .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/umequery/umequery ...
Warning: modules not listed in umecore-hs.cabal for library component (add to other-modules):
    Phonetic.Database.DataTypes
    Phonetic.Database.QueryGenerator
    Phonetic.Database.UmeQueryParser
Warning: modules not listed in umecore-hs.cabal for 'umequery' component (add to other-modules):
    Phonetic.Database.DataTypes
    Phonetic.Database.QueryGenerator
    Phonetic.Database.SegmentList
    Phonetic.Database.UmeQuery
    Phonetic.Database.UmeQueryParser
umecore-hs-0.0.1.0: copy/register
Installing library in
/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/lib/x86_64-osx-ghc-7.10.3/umecore-hs-0.0.1.0-GFN6s0Dt0ywEgbkcE9P2if
Installing executable(s) in
/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/bin
Registering umecore-hs-0.0.1.0...
Completed 3 action(s).
$ ls -al .stack-work/install/x86_64-osx/lts-5.15/7.10.3/bin
total 14352
drwxr-xr-x  3 frkkan96  staff      102 15 Jun 20:54 .
drwxr-xr-x  7 frkkan96  staff      238 15 Jun 20:54 ..
-rwxr-xr-x  1 frkkan96  staff  7347308 15 Jun 20:54 umequery

数据和时间是我运行构建命令时的。

好的,第二个包中对应的section是:

Executable textgrid_import
  Main-Is:        textgrid_import.hs
  Hs-Source-Dirs: src
  default-language:    Haskell2010
  build-depends:       base, filepath, directory, optparse-applicative, umecore-hs

但是,当 linking 二进制文件时,这会失败。 (我包括了详细的输出,因为这是不使用 -v 标志时的建议):

$ stack build fontrans-tools -v
Version 1.1.2, Git revision cebe10e845fed4420b6224d97dcabf20477bbd4b (3646 commits) x86_64 hpack-0.14.0
2016-06-15 21:33:04.098445: [debug] Checking for project config at: /Users/frkkan96/Documents/src/fonetik/stack.yaml @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Config src/Stack/Config.hs:811:9)
2016-06-15 21:33:04.099189: [debug] Loading project config file stack.yaml @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Config src/Stack/Config.hs:829:13)
2016-06-15 21:33:04.100748: [debug] Trying to decode /Users/frkkan96/.stack/build-plan-cache/x86_64-osx/lts-5.15.cache @(stack_JAcs0EuAGbK5rtqRdoxQaL:Data.Binary.VersionTagged src/Data/Binary/VersionTagged.hs:55:5)
2016-06-15 21:33:04.118010: [debug] Success decoding /Users/frkkan96/.stack/build-plan-cache/x86_64-osx/lts-5.15.cache @(stack_JAcs0EuAGbK5rtqRdoxQaL:Data.Binary.VersionTagged src/Data/Binary/VersionTagged.hs:64:13)
2016-06-15 21:33:04.118159: [debug] Getting system compiler version @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Setup src/Stack/Setup.hs:341:17)
2016-06-15 21:33:04.118315: [debug] Run process: ghc --info @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:04.205724: [debug] Asking GHC for its version @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Setup.Installed src/Stack/Setup/Installed.hs:94:13)
2016-06-15 21:33:04.205922: [debug] Run process: ghc --numeric-version @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:04.263388: [debug] Getting Cabal package version @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.GhcPkg src/Stack/GhcPkg.hs:165:5)
2016-06-15 21:33:04.263520: [debug] Run process: ghc-pkg --no-user-package-db field --simple-output Cabal version @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:04.310570: [debug] Resolving package entries @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Setup src/Stack/Setup.hs:221:5)
2016-06-15 21:33:04.310939: [debug] Getting global package database location @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.GhcPkg src/Stack/GhcPkg.hs:48:5)
2016-06-15 21:33:04.311094: [debug] Run process: ghc-pkg --no-user-package-db list --global @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:04.391529: [debug] Run process: ghc-pkg --global --no-user-package-db dump --expand-pkgroot @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:04.448712: [debug] Ignoring package Cabal due to wanting version 1.22.8.0 instead of 1.22.5.0 @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Installed src/Stack/Build/Installed.hs:189:5)
2016-06-15 21:33:04.448902: [debug] Ignoring package haskeline due to wanting version 0.7.2.3 instead of 0.7.2.1 @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Installed src/Stack/Build/Installed.hs:189:5)
2016-06-15 21:33:04.449016: [debug] Ignoring package terminfo due to wanting version 0.4.0.2 instead of 0.4.0.1 @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Installed src/Stack/Build/Installed.hs:189:5)
2016-06-15 21:33:04.449166: [debug] Run process: ghc-pkg --user --no-user-package-db --package-db /Users/frkkan96/.stack/snapshots/x86_64-osx/lts-5.15/7.10.3/pkgdb dump --expand-pkgroot @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:04.514425: [debug] Run process: ghc-pkg --user --no-user-package-db --package-db /Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/pkgdb dump --expand-pkgroot @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:04.561464: [debug] Trying to decode /Users/frkkan96/.stack/indices/Hackage/00-index.cache @(stack_JAcs0EuAGbK5rtqRdoxQaL:Data.Binary.VersionTagged src/Data/Binary/VersionTagged.hs:55:5)
2016-06-15 21:33:04.824920: [debug] Success decoding /Users/frkkan96/.stack/indices/Hackage/00-index.cache @(stack_JAcs0EuAGbK5rtqRdoxQaL:Data.Binary.VersionTagged src/Data/Binary/VersionTagged.hs:64:13)
2016-06-15 21:33:04.839361: [debug] Getting global package database location @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.GhcPkg src/Stack/GhcPkg.hs:48:5)
2016-06-15 21:33:04.839468: [debug] Run process: ghc-pkg --no-user-package-db list --global @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:04.875790: [info] fontrans-tools-0.0.1.0: configure @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:731:23)
2016-06-15 21:33:04.876185: [debug] Run process: /Users/frkkan96/.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 configure --with-ghc=/Applications/ghc-7.10.3.app/Contents/bin/ghc --with-ghc-pkg=/Applications/ghc-7.10.3.app/Contents/bin/ghc-pkg --user --package-db=clear --package-db=global --package-db=/Users/frkkan96/.stack/snapshots/x86_64-osx/lts-5.15/7.10.3/pkgdb --package-db=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/pkgdb --libdir=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/lib --bindir=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/bin --datadir=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/share --libexecdir=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/libexec --sysconfdir=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/etc --docdir=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/doc/fontrans-tools-0.0.1.0 --htmldir=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/doc/fontrans-tools-0.0.1.0 --haddockdir=/Users/frkkan96/Documents/src/fonetik/.stack-work/install/x86_64-osx/lts-5.15/7.10.3/doc/fontrans-tools-0.0.1.0 --dependency=base=base-4.8.2.0-cc43d8e06aa74e9c4c0132becc49ee25 --dependency=directory=directory-1.2.2.0-afaac10d677f7107a807fb2fd0eca9f4 --dependency=filepath=filepath-1.4.0.0-f97d1e4aebfd7a03be6980454fe31d6e --dependency=optparse-applicative=optparse-applicative-0.12.1.0-632ff9350432005d4b6860a3720a6388 --dependency=parsec3=parsec3-1.0.1.8-5688cfaeca7a269c6253ee69a4a21ff3 --dependency=parsec3-numbers=parsec3-numbers-0.1.0-1da0360a989926d6fcebdf3a7f1f97f7 --dependency=text=text-1.2.2.1-3d0a931105ed331bf2fb8b46dcae08ba --dependency=umecore-hs=umecore-hs-0.0.1.0-aa9f7170502bcbb7414f68ed6634ef50 --enable-tests --enable-benchmarks @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:05.517871: [info] Configuring fontrans-tools-0.0.1.0... @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:05.751514: [info] fontrans-tools-0.0.1.0: build @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:731:23)
2016-06-15 21:33:05.751664: [debug] Run process: /Users/frkkan96/.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build lib:fontrans-tools exe:textgrid_import --ghc-options " -ddump-hi -ddump-to-file" @(stack_JAcs0EuAGbK5rtqRdoxQaL:System.Process.Read src/System/Process/Read.hs:283:3)
2016-06-15 21:33:05.822999: [info] Preprocessing library fontrans-tools-0.0.1.0... @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:05.924541: [info] [1 of 1] Compiling Phonetic.IPA.IPAParser ( src/Phonetic/IPA/IPAParser.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/Phonetic/IPA/IPAParser.o ) @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:06.616139: [info] In-place registering fontrans-tools-0.0.1.0... @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:06.616305: [info] Preprocessing executable 'textgrid_import' for fontrans-tools-0.0.1.0... @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:06.702453: [info] [1 of 1] Compiling Main             ( src/textgrid_import.hs, .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/textgrid_import/textgrid_import-tmp/Main.o ) @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:07.173423: [info] Linking .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/build/textgrid_import/textgrid_import ... @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:07.531282: [warn] Undefined symbols for architecture x86_64: @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:07.531443: [warn]   "_umecozuGFN6s0Dt0ywEgbkcE9P2if_PhoneticziDatabaseziDataTypes_UmeQuery_con_info", referenced from: @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:07.531618: [warn]       _ceTP_info in libHSumecore-hs-0.0.1.0-GFN6s0Dt0ywEgbkcE9P2if.a(TextgridParser.o) @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:07.548450: [warn] ld: symbol(s) not found for architecture x86_64 @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)
2016-06-15 21:33:07.552040: [warn] clang: error: linker command failed with exit code 1 (use -v to see invocation) @(stack_JAcs0EuAGbK5rtqRdoxQaL:Stack.Build.Execute src/Stack/Build/Execute.hs:911:67)

--  While building package fontrans-tools-0.0.1.0 using:
      /Users/frkkan96/.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build lib:fontrans-tools exe:textgrid_import --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

为什么同一台机器上的同一个 linker 在第二种情况下无法 link? 我能想到的一件事是第二个包从第一个包加载库,但我认为这应该是可能的,我想?

Fix these warnings first: Warning: modules not listed in umecore-hs.cabal for library component Warning: modules not listed in umecore-hs.cabal for 'umequery' component – thomie Jun 25 at 11:35

我认为@tomie 解决了它。不知道为什么,但是通过显式包含工作包规范的副本来构建第二个可执行文件,然后它开始工作。不知道为什么链接器抱怨而不是编译器,但你去了。有效。