ere*_*wok 6 haskell ghci haskell-stack
尝试使用postgresql-simple在GHCI中创建数据库连接时,我得到GHCI段错误.
我使用的是GHC 8.0.1,OSX 10.11.16.我没有系统GHC,只有堆栈安装的系统.
如果我在我的项目中执行以下操作,则会出现以下错误:
$ stack ghci
Loaded GHCi configuration from /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci62972/ghci-script
gchi> :set -XOverloadedStrings
gchi> import Database.PostgreSQL.Simple
gchi> let connstr = "host=localhost port=5432 user=myusername password=mypass dbname=local"
gchi> conn <- connectPostgreSQL connstr
zsh: segmentation fault stack ghci
Run Code Online (Sandbox Code Playgroud)
我认为它可能值得查看它提到的文件,所以这里有以下内容:
> cat /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci62972/ghci-script
:load "/Users/erewok/projects/haskell/simpleservantblog/app/Main.hs" "Api" "Api.Post" "Api.User" "Config" "Html.Home" "Models.Author" "Models.Post"
:module + Api Api.Post Api.User Config Html.Home Models.Author Models.Post
Run Code Online (Sandbox Code Playgroud)
它是从项目加载的所有模块的列表(编译并运行正常).
这是从启动ghci到seg故障的所有内容的完整输出:
$ stack ghci
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Using main module: 1. Package `simpleservantblog' component exe:simpleservantblog-exe with main-is file: /Users/erewok/projects/haskell/simpleservantblog/app/Main.hs
Configuring GHCi with the following packages: simpleservantblog
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /Users/erewok/.ghci
[1 of 8] Compiling Models.Author ( /Users/erewok/projects/haskell/simpleservantblog/src/Models/Author.hs, interpreted )
[2 of 8] Compiling Models.Post ( /Users/erewok/projects/haskell/simpleservantblog/src/Models/Post.hs, interpreted )
[3 of 8] Compiling Html.Home ( /Users/erewok/projects/haskell/simpleservantblog/src/Html/Home.hs, interpreted )
[4 of 8] Compiling Api.User ( /Users/erewok/projects/haskell/simpleservantblog/src/Api/User.hs, interpreted )
[5 of 8] Compiling Api.Post ( /Users/erewok/projects/haskell/simpleservantblog/src/Api/Post.hs, interpreted )
[6 of 8] Compiling Config ( /Users/erewok/projects/haskell/simpleservantblog/src/Config.hs, interpreted )
[7 of 8] Compiling Api ( /Users/erewok/projects/haskell/simpleservantblog/src/Api.hs, interpreted )
[8 of 8] Compiling Main ( /Users/erewok/projects/haskell/simpleservantblog/app/Main.hs, interpreted )
Ok, modules loaded: Api, Config, Api.Post, Api.User, Html.Home, Models.Post, Models.Author, Main.
Loaded GHCi configuration from /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci64266/ghci-script
gchi> :set -XOverloadedStrings
gchi> import Database.PostgreSQL.Simple
gchi> let connstr = "host=localhost port=5432 user=myusername password=mypass dbname=local"
gchi> conn <- connectPostgreSQL connstr
zsh: segmentation fault stack ghci
Run Code Online (Sandbox Code Playgroud)
更多信息
Postgresql版本:9.5,使用EnterpriseDB安装程序安装
发布我的stack.yaml(在下面)的请求提醒我在尝试安装postgresql-libpq时遇到的问题.这可能是相关的.
Stack.yaml
# This file was automatically generated by stack init
# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/
# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: nightly-2016-08-25
# Local packages, usually specified by relative directory name
packages:
- '.'
- location:
git: https://www.github.com/mattjbray/elm-export
commit: 8868c1f09597f44c2e18e014cd9fbcf8320c3fea
extra-dep: True
- location:
git: https://www.github.com/mattjbray/servant-elm
commit: e13c8def8127ea339e9801d804638854947193e8
extra-dep: True
# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
extra-deps:
- wai-make-assets-0.1.1
# Override default flag values for local packages and extra-deps
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
extra-lib-dirs: [/usr/local/opt/libiconv/lib, /usr/local/lib, /usr/lib]
Run Code Online (Sandbox Code Playgroud)
还使用旋转变压器lts-6.17对GHC 7.10.3进行了段落错误
gchi> conn <- connectPostgreSQL connstr
zsh: segmentation fault stack ghci --resolver lts-6.17
Run Code Online (Sandbox Code Playgroud)
我有一个想法
我认为postgresql-libpq我使用的版本是libiconv.2.dylib为Postgresql 9.4编译而构建的,但我尝试连接的数据库实际上是Postgresql 9.5.这可能是我的问题的原因.
我的灵感来自于这个想法
以下是我尝试进一步调试和/或修复此问题的一些步骤.我首先将Postgresql 9.5 *dylib文件链接到我的/usr/local/lib目录中,以替换与Postgresql 9.4版本链接的旧文件.
$ cd /usr/local/lib
$ sudo ln -s -f /Library/PostgreSQL/9.5/lib/*dylib .
Run Code Online (Sandbox Code Playgroud)
在那之后,我试图强迫stack重建postgresql-libpq,并postgresql-simple以这种方式:
$ stack exec -- ghc-pkg unregister --force postgresql-simple
$ stack exec -- ghc-pkg unregister --force postgresql-libpq
$ rm -rf ~/.stack/precompiled/x86_64-osx/ghc-8.0.1/1.24.0.0/postgresql-libpq-0.9.1.1/
$ rm -rf ~/.stack/precompiled/x86_64-osx/ghc-8.0.1/1.24.0.0/postgresql-simple-0.5.2.*
$ stack build
Run Code Online (Sandbox Code Playgroud)
在那时,它答应我将构建和配置已删除的包.然而,当我运行上面的时候仍然是分段.
在尝试为我的问题生成堆栈跟踪时,我发现可以通过以下方式启动 ghci:
$ stack ghci --ghci-options -fexternal-interpreter
Run Code Online (Sandbox Code Playgroud)
然后,无论出于何种原因,段错误都不会出现,一切都会按预期进行。我不知道其他人是否会觉得这有用。
对我来说奇怪的是,编译和运行代码时没有出现问题。我只在 GHCI 中遇到了问题。
不管怎样,在我找到更多信息或者有人有更好的建议之前,我会继续这样做,这样我就可以继续在 REPL 中测试我想要的内容。