Haskell堆栈没有看到环境模块中提供的libgmp.so.10

时间:2017-07-20 12:51:06

标签: environment-variables haskell-stack

我开始尝试在Linux计算群集上工作,其中某些程序和库通过environment modules系统提供。

我想使用stack安装Haskell程序(我应该说我还不熟悉stack)。

stack作为模块提供,因此在执行module load stack之后,我尝试stack setup失败,抱怨gmp失踪:

$ stack setup
Preparing to install GHC (gmp4) to an isolated location.
This will not interfere with any system-level installation.
Downloaded ghc-gmp4-8.0.1.
Installed GHC.

The GHC located at
/pasteur/homes/bli/.stack/programs/x86_64-linux/ghc-gmp4-8.0.1/bin/ghc
failed to compile a sanity check. Please see:

    http://docs.haskellstack.org/en/stable/install_and_upgrade/

for more information. Exception was:
Running
/pasteur/homes/bli/.stack/programs/x86_64-linux/ghc-gmp4-8.0.1/bin/ghc
/tmp/stack-sanity-check24665/Main.hs -no-user-package-db in directory
/tmp/stack-sanity-check24665/ exited with ExitFailure 1

[1 of 1] Compiling Main             (
/tmp/stack-sanity-check24665/Main.hs, /tmp/stack-sanity-check24665/Main.o )
Linking /tmp/stack-sanity-check24665/Main ...

/usr/bin/ld: cannot find -lgmp
collect2: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)

群集的管理员告诉我,gmp也可以作为环境模块使用,所以在再次尝试之前我做了module load gmp,它似乎有效:

$ stack setup
Writing implicit global project config file to:
/pasteur/homes/bli/.stack/global-project/stack.yaml
Note: You can change the snapshot via the resolver field there.
Using latest snapshot resolver: lts-8.23
Downloaded lts-8.23 build plan.
Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/

Downloading root

Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/

Downloading timestamp

Downloading snapshot

Downloading mirrors

Cannot update index (no local copy)

Downloading index

Updated package list downloaded

Populated index cache.

Preparing to install GHC (gmp4) to an isolated location.
This will not interfere with any system-level installation.
Downloaded ghc-gmp4-8.0.2.
Installed GHC.

stack will use a sandboxed GHC it installed
For more information on paths, see 'stack path' and 'stack exec env'
To use this GHC and packages outside of a project, consider using:
stack ghc, stack ghci, stack runghc, or stack exec

然后我尝试使用stack安装hlint

$ stack install hlint
clock-0.7.2: configure
uniplate-1.6.12: download
clock-0.7.2: build
old-time-1.1.0.3: configure
Package old-time uses a custom Cabal build, but does not use a
custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
old-time-1.1.0.3: build
Package old-time uses a custom Cabal build, but does not use a
custom-setup stanza
uniplate-1.6.12: configure
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
uniplate-1.6.12: build
uniplate-1.6.12: copy/register
Progress: 3/7
--  While building package old-time-1.1.0.3 using:

/tmp/stack8279/old-time-1.1.0.3/.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/setup/setup
--builddir=.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0 build
--ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to:
/pasteur/homes/bli/.stack/global-project/.stack-work/logs/old-time-1.1.0.3.log

    [1 of 2] Compiling Main             (
/tmp/stack8279/old-time-1.1.0.3/Setup.hs,
/tmp/stack8279/old-time-1.1.0.3/.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/setup/Main.o
)
    [2 of 2] Compiling StackSetupShim   (
/pasteur/homes/bli/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs,
/tmp/stack8279/old-time-1.1.0.3/.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/setup/StackSetupShim.o
)
    Linking
/tmp/stack8279/old-time-1.1.0.3/.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/setup/setup
...
    Configuring old-time-1.1.0.3...
    configure: WARNING: unrecognized options: --with-compiler
    checking for gcc... /usr/bin/gcc
    checking whether the C compiler works... yes
    checking for C compiler default output file name... a.out
    checking for suffix of executables...
    checking whether we are cross compiling... no
    checking for suffix of object files... o
    checking whether we are using the GNU C compiler... yes
    checking whether /usr/bin/gcc accepts -g... yes
    checking for /usr/bin/gcc option to accept ISO C89... none needed
    checking how to run the C preprocessor... /usr/bin/gcc -E
    checking for grep that handles long lines and -e... /bin/grep
    checking for egrep... /bin/grep -E
    checking for ANSI C header files... yes
    checking for sys/types.h... yes
    checking for sys/stat.h... yes
    checking for stdlib.h... yes
    checking for string.h... yes
    checking for memory.h... yes
    checking for strings.h... yes
    checking for inttypes.h... yes
    checking for stdint.h... yes
    checking for unistd.h... yes
    checking sys/time.h usability... yes
    checking sys/time.h presence... yes
    checking for sys/time.h... yes
    checking sys/timeb.h usability... yes
    checking sys/timeb.h presence... yes
    checking for sys/timeb.h... yes
    checking time.h usability... yes
    checking time.h presence... yes
    checking for time.h... yes
    checking for ftime... yes
    checking for gmtime_r... yes
    checking for localtime_r... yes
    checking for gettimeofday... yes
    checking whether struct tm is in sys/time.h or time.h... time.h
    checking for struct tm.tm_zone... yes
    checking whether time.h and sys/time.h may both be included... yes
    checking for sys/time.h... (cached) yes
    checking whether altzone is declared... no
    configure: creating ./config.status
    config.status: creating include/HsTimeConfig.h
    configure: WARNING: unrecognized options: --with-compiler
    Building old-time-1.1.0.3...
    Preprocessing library old-time-1.1.0.3...

.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Time_hsc_make:
error while loading shared libraries: libgmp.so.10: cannot open shared
object file: No such file or directory
    running
.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Time_hsc_make
failed (exit code 127)
    command was:
.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Time_hsc_make
 >.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Time.hs


--  While building package clock-0.7.2 using:

/pasteur/homes/bli/.stack/setup-exe-cache/x86_64-linux-gmp4/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2
--builddir=.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0 build
--ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to:
/pasteur/homes/bli/.stack/global-project/.stack-work/logs/clock-0.7.2.log

    Configuring clock-0.7.2...
    Building clock-0.7.2...
    Preprocessing library clock-0.7.2...
    Clock.hsc:44:1: warning: "hsc_alignment" redefined
    In file included from
.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Clock_hsc_make.c:1:

/pasteur/homes/bli/.stack/programs/x86_64-linux/ghc-gmp4-8.0.2/lib/ghc-8.0.2/template-hsc.h:88:1:
warning: this is the location of the previous definition

.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Clock_hsc_make:
error while loading shared libraries: libgmp.so.10: cannot open shared
object file: No such file or directory
    running
.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Clock_hsc_make
failed (exit code 127)
    command was:
.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Clock_hsc_make
 >.stack-work/dist/x86_64-linux-gmp4/Cabal-1.24.2.0/build/System/Clock.hs

似乎在编译ghc时,stack能够看到gmp,但在安装某些软件包时却看不到。

我注意到这个警告:configure: WARNING: unrecognized options: --with-compiler。我不知道这是否相关。

环境模块系统似乎可以通过导出一些环境变量来实现:

$ module show gmp
-------------------------------------------------------------------
/local/gensoft2/devmodules/gmp/6.0.0:

module-whatis    Set environnement for gmp (6.0.0) 
module-whatis    topic_3316 
prepend-path     LIBRARY_PATH /local/gensoft2/lib/gmp/6.0.0/lib 
prepend-path     LD_RUN_PATH /local/gensoft2/lib/gmp/6.0.0/lib 
prepend-path     -d   LDFLAGS -L/local/gensoft2/lib/gmp/6.0.0/lib 
prepend-path     CMAKE_LIBRARY_PATH /local/gensoft2/lib/gmp/6.0.0/lib 
prepend-path     C_INCLUDE_PATH /local/gensoft2/lib/gmp/6.0.0/include 
prepend-path     CPLUS_INCLUDE_PATH /local/gensoft2/lib/gmp/6.0.0/include 
prepend-path     CMAKE_INCLUDE_PATH /local/gensoft2/lib/gmp/6.0.0/include 
prepend-path     -d   CPPFLAGS -I/local/gensoft2/lib/gmp/6.0.0/include 
setenv       GMP_ROOT /local/gensoft2/lib/gmp/6.0.0 
-------------------------------------------------------------------

管理员告诉我,这些环境变量并不总是被考虑在内,并建议在尝试之前在我的环境中导出LDFLAGS="-Wl,-rpath,$GMP_ROOT/lib $LDFLAGS",但这似乎对此问题没有任何影响。

我仍然获得以下内容:error while loading shared libraries: libgmp.so.10: cannot open shared object file: No such file or directory

如何让stack可靠地考虑环境模块系统提供的开发库?

修改

似乎我可以将命令行中缺少的库路径提供给stack,如下所示:

$ stack --extra-lib-dirs=/local/gensoft2/lib/gmp/6.0.0/lib --extra-include-dirs=/local/gensoft2/lib/gmp/6.0.0/include install hlint
old-time-1.1.0.3: configure
Package old-time uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
old-time-1.1.0.3: build
Package old-time uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
clock-0.7.2: configure
clock-0.7.2: build
clock-0.7.2: copy/register
extra-1.5.3: download
extra-1.5.3: configure
extra-1.5.3: build
old-time-1.1.0.3: copy/register
Package old-time uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
Package old-time uses a custom Cabal build, but does not use a custom-setup stanza
Not using the explicit setup deps approach based on configuration
Strongly recommend fixing the package's cabal file
cpphs-1.20.8: download
cpphs-1.20.8: configure
cpphs-1.20.8: build
extra-1.5.3: copy/register
cpphs-1.20.8: copy/register
haskell-src-exts-1.18.2: download
haskell-src-exts-1.18.2: configure
haskell-src-exts-1.18.2: build
haskell-src-exts-1.18.2: copy/register
hlint-1.9.41: download
hlint-1.9.41: configure
hlint-1.9.41: build
hlint-1.9.41: copy/register
Completed 6 action(s).
Copying from /pasteur/homes/bli/.stack/snapshots/x86_64-linux-gmp4/lts-8.23/8.0.2/bin/hlint to /pasteur/homes/bli/.local/bin/hlint

Copied executables to /pasteur/homes/bli/.local/bin:
- hlint

有没有办法让module加载的每个可能的开发库自动完成?

1 个答案:

答案 0 :(得分:0)

我不确定这是完全可靠的(开发库的环境模块可能都不会导出这些变量),但将-extra-include-dirs=${CMAKE_INCLUDE_PATH}--extra-lib-dirs=${CMAKE_LIBRARY_PATH}传递给stack似乎至少可行安装hlintscandoctest

我对使用的正确配置文件以及如何使其自动化感到困惑。

似乎考虑了~/.stack/config.yaml中的相应设置(尽管documentation提及~/.stack/global-project/stack.yaml)。

上述环境变量不能在配置文件中原样使用。我还没确定究竟是什么原因。这可能是因为它们的扩展导致语法不正确(路径用“:”而不是“,”分隔),或者因为配置文件中只允许纯文本。

因此,以下情况适用于本案,但不是一般解决方案:

extra-include-dirs: [/local/gensoft2/lib/gmp/6.0.0/include]
extra-lib-dirs: [/local/gensoft2/lib/gmp/6.0.0/lib]