2017-11-30 7 views
4

스택이있는 Haskell 프로젝트에서 req 패키지 (http://hackage.haskell.org/package/req)를 사용하려고합니다.Archlinux에서`/ usr/bin/ld : final link failed '로 스택 빌드가 실패했습니다

지금까지 나는 stack new my-project, stack setup, stack buildstack exec my-project-exe을 모두 사용해 왔습니다.

name:    my-project 
version:    0.1.0.0 
synopsis:   Short description of your package 
homepage:   https://github.com/githubuser/#readme 
license:    BSD3 
license-file:  LICENSE 
author:    Author name here 
maintainer:   [email protected] 
copyright:   2017 Author name here 
category:   Web 
build-type:   Simple 
extra-source-files: README.md 
cabal-version:  >=1.10 


library 
    hs-source-dirs:  src 
    exposed-modules:  Lib 
    build-depends:  base >= 4.7 && < 5 
        , req -- THIS IS THE LINE IVE ADDED 
    default-language: Haskell2010 

executable my-project-exe 
    hs-source-dirs:  app 
    main-is:    Main.hs 
    ghc-options:   -threaded -rtsopts -with-rtsopts=-N 
    build-depends:  base 
        , my-project 
    default-language: Haskell2010 

test-suite my-project-test 
    type:    exitcode-stdio-1.0 
    hs-source-dirs:  test 
    main-is:    Spec.hs 
    build-depends:  base 
        , my-project 
    ghc-options:   -threaded -rtsopts -with-rtsopts=-N 
    default-language: Haskell2010 

source-repository head 
    type:  git 
    location: https://github.com/githubuser/my-project 

을 그리고 마지막으로,과 같이 함수 이름을 변경, 잘라 src/Lib.hs에 REQ의 추가 정보에서 예를 붙여 넣습니다 :

지금처럼 음모 파일에 req을 추가 한

{-# LANGUAGE OverloadedStrings #-} 
{-# OPTIONS_GHC -fno-warn-orphans #-} 

module Lib 
    (someFunc 
    ) where 

import Control.Exception (throwIO) 
import Network.HTTP.Req 
import Data.Aeson 

-- Just make your monad stack an instance of MonadHttp in your application 
-- and start making requests, enjoy automatic connection sharing. 

instance MonadHttp IO where 
    handleHttpException = throwIO 

someFunc :: IO() 
someFunc = do 
    let payload = object 
     [ "foo" .= (10 :: Int) 
     , "bar" .= (20 :: Int) ] 
    -- One function, full power and flexibility. 
    r <- req POST -- method 
    (https "httpbin.org" /: "post") -- safe by construction URL 
    (ReqBodyJson payload) -- use built-in options or add your own 
    jsonResponse -- specify how to interpret response 
    mempty  -- query params, headers, explicit port number, etc. 
    print (responseBody r :: Value) 

그리고 지금 stack build이 오류입니다 :

%> stack build 
basement-0.0.4: configure 
basement-0.0.4: build 
zlib-0.6.1.2: configure 
aeson-1.1.2.0: download 
zlib-0.6.1.2: build 
network-2.6.3.2: configure 
th-lift-instances-0.1.11: download 
aeson-1.1.2.0: configure 
aeson-1.1.2.0: build 
th-lift-instances-0.1.11: configure 
th-lift-instances-0.1.11: build 
th-lift-instances-0.1.11: copy/register 
aeson-1.1.2.0: copy/register 
Progress: 5/28 
-- While building package network-2.6.3.2 using: 
     /tmp/stack7830/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/setup --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 configure --with-ghc=/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/bin/ghc --with-ghc-pkg=/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/bin/ghc-pkg --user --package-db=clear --package-db=global --package-db=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/pkgdb --libdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/lib --bindir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/bin --datadir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/share --libexecdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/libexec --sysconfdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/etc --docdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/doc/network-2.6.3.2 --htmldir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/doc/network-2.6.3.2 --haddockdir=/home/liam/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-9.14/8.0.2/doc/network-2.6.3.2 --dependency=base=base-4.9.1.0 --dependency=bytestring=bytestring-0.10.8.1 --dependency=unix=unix-2.7.2.1 
    Process exited with code: ExitFailure 1 
    Logs have been written to: /home/liam/code/forecast-compare/.stack-work/logs/network-2.6.3.2.log 

    [1 of 2] Compiling Main    (/tmp/stack7830/network-2.6.3.2/Setup.hs, /tmp/stack7830/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/Main.o) 
    [2 of 2] Compiling StackSetupShim (/home/liam/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /tmp/stack7830/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/StackSetupShim.o) 
    Linking /tmp/stack7830/network-2.6.3.2/.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/setup/setup ... 
    Configuring network-2.6.3.2... 
    configure: WARNING: unrecognized options: --with-compiler 
    checking build system type... x86_64-pc-linux-gnu 
    checking host system type... x86_64-pc-linux-gnu 
    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... configure: error: in `/tmp/stack7830/network-2.6.3.2': 
    configure: error: cannot run C compiled programs. 
    If you meant to cross compile, use `--host'. 
    See `config.log' for more details 


-- While building package zlib-0.6.1.2 using: 
     /home/liam/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file" 
    Process exited with code: ExitFailure 1 
    Logs have been written to: /home/liam/code/forecast-compare/.stack-work/logs/zlib-0.6.1.2.log 

    Configuring zlib-0.6.1.2... 
    Building zlib-0.6.1.2... 
    Preprocessing library zlib-0.6.1.2... 
    /usr/bin/ld: .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_make.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC 
    /usr/bin/ld: final link failed: Nonrepresentable section on output 
    collect2: error: ld returned 1 exit status 
    linking .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_make.o failed (exit code 1) 
    command was: /usr/bin/gcc .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_make.o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_utils.o -o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Codec/Compression/Zlib/Stream_hsc_make -fno-PIE -fno-stack-protector -lz -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/bytestring-0.10.8.1 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/bytestring-0.10.8.1 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/deepseq-1.4.2.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/deepseq-1.4.2.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/array-0.5.1.1 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/array-0.5.1.1 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -lgmp -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -lm -lrt -ldl -lpthread 


-- While building package basement-0.0.4 using: 
     /home/liam/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file" 
    Process exited with code: ExitFailure 1 
    Logs have been written to: /home/liam/code/forecast-compare/.stack-work/logs/basement-0.0.4.log 

    Configuring basement-0.0.4... 
    Building basement-0.0.4... 
    Preprocessing library basement-0.0.4... 
    /usr/bin/ld: .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_make.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC 
    /usr/bin/ld: final link failed: Nonrepresentable section on output 
    collect2: error: ld returned 1 exit status 
    linking .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_make.o failed (exit code 1) 
    command was: /usr/bin/gcc .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_make.o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_utils.o -o .stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0/build/Basement/Terminal/Size_hsc_make -fno-PIE -fno-stack-protector -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/base-4.9.1.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/integer-gmp-1.0.0.1 -lgmp -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/ghc-prim-0.5.0.0 -L/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -Wl,-R,/home/liam/.stack/programs/x86_64-linux/ghc-tinfo6-nopie-8.0.2/lib/ghc-8.0.2/rts -lm -lrt -ldl -lpthread 

많은 도움을 주셨습니다!

+0

archlinux를 사용하고 있습니까? AUR에서 ncurses5-compat-libs를 설치하고'ghc-build : nopie'를 stack.yaml에 추가하거나 다른 프로젝트에서이 문제를 방지하려면'~/.stack/config '에 추가하십시오. yaml' – Zpalmtree

+0

저는 실제로 아치 리눅스를 사용하고 있습니다. - 언급 했음에 틀림 없습니다. 고마워,이 일했다! – ljw

+0

좋아요! 나는이 문제를 우연히 만난 다른 사용자를 돕기 위해 좀 더 심층적 인 대답을 덧붙였다. – Zpalmtree

답변

2

이 문제는 아치 리눅스 사용자를 몇 달 동안 괴롭 히고 있습니다. 이것은 ncurses 라이브러리와 관련이있는 것으로 보이며, 아마도 대부분의 (모든?) 다른 배포판이 정적 링크를 사용하는 반면 Haskell 패키지를 동적으로 연결하는 아치 리눅스 때문입니다.

현재 해결 방법은 스택 ghc 버전에 ghc-build: nopie 옵션을 사용하고 AUR에서 ncurses5-compat-libs을 설치하는 것입니다.

전역으로 설정하려면 ~/.stack/config.yaml에 설정할 수 있으므로 스택으로 빌드 한 모든 프로젝트에 적용됩니다.

버그 신고는 현재 here이며, 일부 관련 토론은 arch forums 또는 stack github에서 찾을 수 있습니다. 나를 ~/.stack을 삭제하고

stack setup --ghc-build=ncurses6 

을 사용하고

ghc-build: ncurses6 

~/.stack/config.yaml 

에이 해결 추가에 대한

1

.

은 부록 :

ghc-build: tinfo6 

stack setup --ghc-build=tinfo6 

나를 위해 더 나은했다.