首页 > 解决方案 > 无法使用堆栈构建带有模块导入的项目(在 Windows 上)

问题描述

我做了一个培训项目,需要几个模块导入(其中包括 Database.Redis 和 Web.Scotty)。当我这样做时,stack build我得到了这个:

D:\ssd-data\work\my-project\my-project.cabal was modified manually. Ignoring D:\ssd-data\work\my-project\package.yaml in favor of the cabal file.
If you want to use the package.yaml file instead of the cabal file,
then please delete the cabal file.
Stack has not been tested with GHC versions above 8.6, and using 8.8.3, this may fail
Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 was found, this may fail
WARNING: Ignoring regex-posix's bounds on base (<0 && >=4.3 && <4.14); using base-4.13.0.0.
Reason: trusting snapshot over cabal file dependency information.
regex-posix      > configure
regex-posix      > Configuring regex-posix-0.96.0.0...
regex-posix      > build
regex-posix      > Preprocessing library for regex-posix-0.96.0.0..
regex-posix      > C:\Users\user\AppData\Local\Temp\stack3628\regex-posix-0.96.0.0\Wrap.hsc:96:10: fatal error: regex.h: No such file or directory
regex-posix      > compilation terminated.
regex-posix      > compiling .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.c failed (exit code 1)
regex-posix      > command was: C:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\../mingw/bin\gcc.exe -c .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.c -o .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.o -D__GLASGOW_HASKELL__=808 -Dmingw32_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dmingw32_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\29cc6475\build\cbits -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\29cc6475\build\autogen -I.stack-work\dist\29cc6475\build\global-autogen -include .stack-work\dist\29cc6475\build\autogen\cabal_macros.h -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\bytestring-0.10.10.0\include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\base-4.13.0.0\include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\integer-gmp-1.0.2.0\include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib/include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3/lib/include/
streaming-commons> configure
streaming-commons> Configuring streaming-commons-0.2.1.2...
streaming-commons> build
streaming-commons> Preprocessing library for streaming-commons-0.2.1.2..
streaming-commons> Building library for streaming-commons-0.2.1.2..
streaming-commons> [ 1 of 17] Compiling Data.Streaming.ByteString.Builder.Buffer
streaming-commons> [ 2 of 17] Compiling Data.Streaming.ByteString.Builder
streaming-commons> [ 3 of 17] Compiling Data.Streaming.Filesystem
streaming-commons> [ 4 of 17] Compiling Data.Streaming.Network.Internal
streaming-commons> [ 5 of 17] Compiling Data.Streaming.Network
streaming-commons> [ 6 of 17] Compiling Data.Streaming.Process.Internal
streaming-commons> [ 7 of 17] Compiling Data.Streaming.Process
streaming-commons> [ 8 of 17] Compiling Data.Streaming.Zlib.Lowlevel
streaming-commons> [ 9 of 17] Compiling Data.Streaming.Zlib
streaming-commons> [10 of 17] Compiling Data.Text.Internal.Encoding.Utf16
streaming-commons> [11 of 17] Compiling Data.Text.Internal.Encoding.Utf32
streaming-commons> [12 of 17] Compiling Data.Text.Internal.Unsafe.Shift
streaming-commons> [13 of 17] Compiling Data.Text.Internal.Unsafe.Char
streaming-commons> [14 of 17] Compiling Data.Text.Internal.Encoding.Utf8
streaming-commons> [15 of 17] Compiling Data.Streaming.Text
streaming-commons> [16 of 17] Compiling System.Win32File
streaming-commons> [17 of 17] Compiling Data.Streaming.FileRead
streaming-commons> copy/register
streaming-commons> Installing library in C:\sr\snapshots\260bc685\lib\x86_64-windows-ghc-8.8.3\streaming-commons-0.2.1.2-7nSvofLzcDVEO2jjCYKFuK
streaming-commons> Registering library for streaming-commons-0.2.1.2..

--  While building package regex-posix-0.96.0.0 using:
      C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.0.1.0_ghc-8.8.3.exe --builddir=.stack-work\dist\29cc6475 build --ghc-options ""
    Process exited with code: ExitFailure 1
Progress 2/9

当我构建一个没有任何导入的项目时,一切都很好。

标签: haskellghchaskell-stack

解决方案


我有同样的问题,但我解决了。如果您还没有解决问题,我认为您可以按照我的做法解决问题。

错误消息中最重要的部分如下。关键是缺少头文件(regex.h),您必须将其添加到正确的路径中。

regex-posix      > ...\regex-posix-0.96.0.0\Wrap.hsc:96:10: fatal error: 
                   regex.h: No such file or directory    
regex-posix      > compilation terminated.
...
regex-posix      > command was: C:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\../mingw/bin\gcc.exe -c .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.c -o .stack-work\dist\29cc6475\build\Text\Regex\Posix\Wrap_hsc_make.o -D__GLASGOW_HASKELL__=808 -Dmingw32_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dmingw32_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\29cc6475\build\cbits -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\29cc6475\build\autogen -I.stack-work\dist\29cc6475\build\global-autogen -include .stack-work\dist\29cc6475\build\autogen\cabal_macros.h -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\bytestring-0.10.10.0\include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\base-4.13.0.0\include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\integer-gmp-1.0.2.0\include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib/include -IC:\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3/lib/include/

您可以从https://code.woboq.org/linux/include/regex.h.html获取regex.h文件。将文件保存到上述错误消息(最后一行)所示的路径中。在您的情况下,路径是:

\Users\user\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\include

重要的是把 regex.h 文件放在 Haskell 的库文件夹中。( ...\x86_64-windows\ghc-8.8.3\lib\include ) 之后,执行堆栈构建命令。

希望我的回答对你有帮助。


推荐阅读