除非以管理员身份运行,否则堆栈 ghci 无法加载 pthread

Mar*_*ann 7 haskell haskell-stack

当我stack ghci在一个全新的项目上运行时,它无法加载:

$ stack new repro simple
Downloading template "simple" to create project "repro" in repro\ ...
Run Code Online (Sandbox Code Playgroud)

(省略了额外的输出以使问题更具可读性。)

$ cd repro/

$ stack ghci
Using main module: 1. Package `repro' component repro:exe:repro with main-is file: C:\Users\mark\Desktop\repro\src\Main.hs
Building all executables for `repro' once. After a successful build of all of them, only specified executables will be rebuilt.
repro> configure (exe)
Configuring repro-0.1.0.0...
repro> initial-build-steps (exe)
Configuring GHCi with the following packages: repro
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
<command line>: user specified .o/.so/.DLL could not be loaded (addDLL: pthread or dependencies not loaded. (Win32 error 5))
Whilst trying to load:  (dynamic) pthread
Additional directories searched:   C:\\Users\\mark\\AppData\\Local\\Programs\\stack\\x86_64-windows\\msys2-20180531\\mingw64\\lib
   C:\\Users\\mark\\AppData\\Local\\Programs\\stack\\x86_64-windows\\msys2-20180531\\mingw64\\bin
   C://Users//mark//AppData//Local//Programs//stack//x86_64-windows//ghc-8.6.5//mingw//bin/
   C://Users//mark//AppData//Local//Programs//stack//x86_64-windows//ghc-8.6.5//mingw//bin/../lib/
   C://Users//mark//AppData//Local//Programs//stack//x86_64-windows//ghc-8.6.5//mingw//bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/
   C:/Users/mark/AppData/Local/Programs/stack/x86_64-windows/ghc-8.6.5/mingw/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/
   C:/Users/mark/AppData/Local/Programs/stack/x86_64-windows/ghc-8.6.5/mingw/bin/../lib/gcc/
   C:/Users/mark/AppData/Local/Programs/stack/x86_64-windows/ghc-8.6.5/mingw/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/
   C:/Users/mark/AppData/Local/Programs/stack/x86_64-windows/ghc-8.6.5/mingw/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../lib/
   C:/Users/mark/AppData/Local/Programs/stack/x86_64-windows/ghc-8.6.5/mingw/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/
   C:/Users/mark/AppData/Local/Programs/stack/x86_64-windows/ghc-8.6.5/mingw/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../
   C:\Windows\system32
Run Code Online (Sandbox Code Playgroud)

这是在 Windows 10 (x64) 上。我有另一台具有类似操作系统配置和堆栈版本的机器,在那台机器上,我没有问题。这似乎是一个环境问题,但我无法弄清楚它是什么。

我从Git Bash运行,如果我以管理员身份运行它,它可以工作:

$ stack ghci
Using main module: 1. Package `repro' component repro:exe:repro with main-is file: C:\Users\mark\Desktop\repro\src\Main.hs
Building all executables for `repro' once. After a successful build of all of them, only specified executables will be rebuilt.
repro> initial-build-steps (exe)
Configuring GHCi with the following packages: repro
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( C:\Users\mark\Desktop\repro\src\Main.hs, interpreted )
Ok, one module loaded.
Loaded GHCi configuration from C:\\Users\\mark\\AppData\\Local\\Temp\\haskell-stack-ghci\\2524149e\\ghci-script
*Main>
Run Code Online (Sandbox Code Playgroud)

我多年来一直在 Windows 上使用 Stack,这是我第一次必须以管理员身份运行,这真的让我很困扰。可能是什么问题,我该如何解决?

FWIW,这是堆栈版本:

$ stack --version
Version 2.1.3, Git revision 0fa51b9925decd937e4a993ad90cb686f88fa282 (7739 commits) x86_64 hpack-0.31.2
Run Code Online (Sandbox Code Playgroud)

这与我在另一台没有出现问题的机器上的版本相同。

这里的示例是从运行Git Bash复制而来的,但如果我使用cmd.

Mar*_*ann 6

感谢 Fyodor Soikin,我能够追踪到这个问题。

概括

授予您的用户帐户Read & execute权限pthread.dll

细节

我不明白为什么我的这台新机器会出现这个问题,而另一台具有相同操作系统和基本相同设置的机器却没有任何问题。

仔细检查,原来那台机器根本没有pthread.dll文件

不过,它确实有相当多的副本pthread.h,我想这足以让Stack构建代码。

新机器有pthread.dll几个地方,包括一个子目录C:\Windows\System32\DriverStore,这对我来说意味着这个文件最初是通过新机器使用的驱动程序到达的,但旧机器没有。它也有一个pthread.dllin的副本C:\Windows\System32,但是这个文件被异常锁定。我自己的用户帐户没有ReadExecute权限,该文件,但我可以查看和更改的权限管理模式。

我授予了本地用户Read & execute对该文件的权限,之后一切似乎都像以前在我的其他机器上所做的那样工作。