winterland1989 / magic-haskell

魔力haskell官方网站
293 stars 28 forks source link

cabal build问题? #14

Closed boboyada closed 7 years ago

boboyada commented 7 years ago

git clone https://github.com/winterland1989/magic-haskell.git cd ./magic-haskell/code cabal sandbox init cabal install --only-dependencies 都可以通过了 但cabal build 有问题 C:\Users\yangboant\magic-haskell\code>cabal build Building code-0.1.0.0... Preprocessing executable 'arg-parser' for code-0.1.0.0...

: error: output was redirected with -o, but no output will be generated because there is no Main module.
winterland1989 commented 7 years ago

你把ArgParser.hs文件的第一行改成module Main where可以么?另外你的cabal是什么版本的?

boboyada commented 7 years ago

我在windows10环境里,安装的是最新的haskell-playform 8.01,cabal 升级到了最新的版本。

另外,在ubuntu 16.10的环境下,通过sudo apt install haskell-platform,安装的是7。10。3版本,cabal是1。22。9的版本。出现的问题,则更多些。 boboant@boboant-ThinkPad-W530:~/magic-haskell/code$ sudo cabal install --only-dependencies Resolving dependencies... cabal: Could not resolve dependencies: trying: code-0.1.0.0 (user goal) trying: base-4.8.2.0/installed-0d6... (dependency of code-0.1.0.0) trying: monad-logger-0.3.20.1 (dependency of code-0.1.0.0) trying: conduit-extra-1.1.15 (dependency of monad-logger-0.3.20.1) trying: primitive-0.6.2.0 (dependency of conduit-extra-1.1.15) trying: attoparsec-0.13.1.0 (dependency of conduit-extra-1.1.15) trying: scientific-0.3.4.9 (dependency of attoparsec-0.13.1.0) next goal: vector (dependency of scientific-0.3.4.9) rejecting: vector-0.11.0.0, 0.10.12.3 (conflict: primitive==0.6.2.0, vector => primitive>=0.5.0.1 && <0.6.2) rejecting: vector-0.10.12.2, 0.10.12.1, 0.10.11.0, 0.10.10.0, 0.10.9.2, 0.10.9.1, 0.10.9.0 (conflict: primitive==0.6.2.0, vector => primitive>=0.5.0.1 && <0.6) rejecting: vector-0.10.0.1, 0.10 (conflict: base==4.8.2.0/installed-0d6..., vector => base>=4 && <4.7) rejecting: vector-0.9.1, 0.9 (conflict: primitive==0.6.2.0, vector => primitive>=0.4.0.1 && <0.5) rejecting: vector-0.8 (conflict: primitive==0.6.2.0, vector => primitive>=0.4 && <0.5) rejecting: vector-0.7.1, 0.7.0.1, 0.7 (conflict: primitive==0.6.2.0, vector => primitive>=0.3.1 && <0.4) rejecting: vector-0.6.0.2, 0.6.0.1, 0.6 (conflict: primitive==0.6.2.0, vector => primitive>=0.3 && <0.4) rejecting: vector-0.5 (conflict: primitive==0.6.2.0, vector => primitive>=0.2 && <0.3) rejecting: vector-0.4.2, 0.4.1, 0.4, 0.3.1, 0.3, 0.2, 0.1 (conflict: scientific => vector>=0.5 && <0.12) rejecting: vector-0.10.12.0, 0.10.9.3 (conflict: primitive==0.6.2.0, vector => primitive>=0.5.0.1 && <0.6) Backjump limit reached (change with --max-backjumps).

Note: when using a sandbox, all packages are required to have consistent dependencies. Try reinstalling/unregistering the offending packages or recreating the sandbox.

boboyada commented 7 years ago
   所以,如果可能的话,还请您再费些心力把版本依赖适当调整一下。我是初学者,对语言和整个环境也不了解,解决起来更是吃力。如果我在学习过程中遇到的问题,其它初学者,大部分也都有这个可能。就怕读者不反馈:)))
  老实说,您的这本书写得真是相当不赖,我之前也读过张松的,但一直无法看下去。只有读了您的书,我才有兴趣边学边看看代码

辛苦您了!

winterland1989 commented 7 years ago

我自己试了一下,除了之前你说的transformer的版本限制需要放宽之外(已经修改), 最容易产生问题的是下面这个范例:

executable database
  main-is:             Database.hs
  -- other-modules:       
  build-depends:       base >=4.7 && <5
                       , transformers
                       , persistent >=2.1 
                       , persistent-sqlite >=2.1 
                       , persistent-template >=2.1
                       , monad-logger >=0.3 
                       , esqueleto >= 2.4
  default-language:    Haskell2010

报错的原因是esqueleto已经暂停维护接近一年了,详见https://github.com/prowdsponsor/esqueleto/issues/137 , 导致它的很多递归依赖已经和最新的版本冲突了,好在目前已经有人准备接手更新这个函数库了。这里暂时建议你把上面那一段从cabal文件里删掉,以免影响其他范例,等到esqueleto发版之后我会尽快补上新的版本范围。开源社区就是这样,很多时候都取决于贡献者的业余时间,所以也请谅解。

boboyada commented 7 years ago

按照你的建议,我把code.sandbox中的database模块删除了, sudo cabal install --only dependencies 一切正常。 但是,运行如下命令时,却出现奇怪的错误 请问您是在哪些环境下调试成功的? sudo cabal build The sandbox was created after the package was already configured. Re-configuring with most recently used options. If this fails, please run configure manually. Resolving dependencies... Configuring code-0.1.0.0... Building code-0.1.0.0... Preprocessing executable 'arg-parser' for code-0.1.0.0... [1 of 1] Compiling ArgParser ( ArgParser.hs, dist/build/arg-parser/arg-parser-tmp/ArgParser.o )

ArgParser.hs:13:5: Not in scope: ‘<>’ Perhaps you meant one of these: ‘<$>’ (imported from Options.Applicative), ‘<*>’ (imported from Options.Applicative), ‘<|>’ (imported from Options.Applicative)

ArgParser.hs:14:5: Not in scope: ‘<>’ Perhaps you meant one of these: ‘<$>’ (imported from Options.Applicative), ‘<*>’ (imported from Options.Applicative), ‘<|>’ (imported from Options.Applicative)

ArgParser.hs:18:5: Not in scope: ‘<>’ Perhaps you meant one of these: ‘<$>’ (imported from Options.Applicative), ‘<*>’ (imported from Options.Applicative), ‘<|>’ (imported from Options.Applicative)

ArgParser.hs:24:9: Not in scope: ‘<>’ Perhaps you meant one of these: ‘<$>’ (imported from Options.Applicative), ‘<*>’ (imported from Options.Applicative), ‘<|>’ (imported from Options.Applicative)

ArgParser.hs:25:9: Not in scope: ‘<>’ Perhaps you meant one of these: ‘<$>’ (imported from Options.Applicative), ‘<*>’ (imported from Options.Applicative), ‘<|>’ (imported from Options.Applicative)

ArgParser.hs:32:9: Not in scope: ‘<>’ Perhaps you meant one of these: ‘<$>’ (imported from Options.Applicative), ‘<*>’ (imported from Options.Applicative), ‘<|>’ (imported from Options.Applicative)

ArgParser.hs:33:9: Not in scope: ‘<>’ Perhaps you meant one of these: ‘<$>’ (imported from Options.Applicative), ‘<*>’ (imported from Options.Applicative), ‘<|>’ (imported from Options.Applicative) boboant@boboant-ThinkPad-W530:~/magic-haskell/code$

boboyada commented 7 years ago

单独进入ghci, :load Lens 则可以正常运行。但无法按照readme的指令正常进行。还望作者帮助

winterland1989 commented 7 years ago

提示当前没有<>函数貌似是因为opts-applicative的一次breaking change之后不再导出,你只需要在ArgParser.hs文件的导入列表里新增如下导入即可:

import Data.Monoid

PS:建议lz好好读读我的书哈,看到第三部分的第一章之后你就会发现这些错误信息其实都蛮好解决的。

boboyada commented 7 years ago

谢放。确实,在添加后,确实没有错了。 但 执行如下命令运行范例:

第12章 透镜组

cabal run -- lens

sudo cabal run -- lens Preprocessing executable 'lens' for code-0.1.0.0... Warning: output was redirected with -o, but no output will be generated because there is no Main module. cabal: dist/build/lens/lens: does not exist

sudo cabal run -- arg-parser Preprocessing executable 'arg-parser' for code-0.1.0.0... Warning: output was redirected with -o, but no output will be generated because there is no Main module. cabal: dist/build/arg-parser/arg-parser: does not exist

sudo cabal run -- queens Preprocessing executable 'queens' for code-0.1.0.0... Warning: output was redirected with -o, but no output will be generated because there is no Main module. cabal: dist/build/queens/queens: does not exist

winterland1989 commented 7 years ago

首先我不是很理解此处你为什么需要sudo,这样的话很容易把文件夹的权限弄乱产生难以理解的错误,其次就是你试着把要运行的模块里的module XXX改成module Main试试,似乎你的cabal版本不支持非Main模块包含main函数。

PS: 我想我们的讨论还是转移到电邮比较好,这个repo的follower大部分是希望看到新的资料更新,或者是勘误更新的,类似你的这些问题并不是每个人都会遇到,所以麻烦把你的邮箱给我一下,如果你不习惯电邮的话,我可以通过邮箱发你我的微信或者QQ。

boboyada commented 7 years ago

https://www.haskell.org/cabal/download.html 1、 $cabal install cabal cabal-install 出现 Resolving dependencies... cabal: Could not resolve dependencies: trying: cabal-0.0.0.0 (user goal) next goal: youProbablyWantCapitalCabal (dependency of cabal-0.0.0.0) Dependency tree exhaustively searched. 无法升级, 2、cabal install cabal-install 成功,但是两者有和区别?,是否一个东西? $cabal --version cabal-install version 1.22.6.0 using version 1.22.5.0 of the Cabal library 还是老版本 3、网上也没有找到方案,请帮忙?

winterland1989 commented 7 years ago

请使用邮箱(drkoster@qq.com)联系,谢谢!