qfpl / applied-fp-course

Applied Functional Programming Course - Move from exercises to a working app!
http://qfpl.io/projects/professional-fp-courses/
Other
624 stars 181 forks source link

[stack build] linking failures related to -threaded #45

Closed kevroletin closed 6 years ago

kevroletin commented 6 years ago

Problem:

Both stack build and stack test fail with undefined references to pthread symbols. I can fix stack build by adding ghc-options: -threaded option into executable section of a .cabal file. But similar trick doesn't work for a test-suite section. So I don't sure where exact issue is:

I successfully built and tested all sections using nix-shell, and I used stack primarily for tooling. So this problem isn't a blocker since there are nix build files.

My environment

stack --version
Version 1.7.0, Git revision 066e7ce0c0f82dbc914a3e7be51fc356b42df737 x86_64 hpack-0.20.0
lsb_release -d
Description:    Ubuntu 17.10

Error message

$  level04 [master] ⚡ stack test

Warning: File listed in level04.cabal file does not exist: ChangeLog.md
hspec-discover-2.4.4: configure
hspec-discover-2.4.4: build
Progress 1/4
--  While building custom Setup.hs for package hspec-discover-2.4.4 using:
      /home/behemoth/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.0.1.0 build --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/behemoth/Scratch/haskell/applied-fp-course_fix/level04/.stack-work/logs/hspec-discover-2.4.4.log

    Configuring hspec-discover-2.4.4...
    Preprocessing library for hspec-discover-2.4.4..
    Building library for hspec-discover-2.4.4..
    [1 of 3] Compiling Paths_hspec_discover ( .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/autogen/Paths_hspec_discover.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/Paths_hspec_discover.o )
    [2 of 3] Compiling Test.Hspec.Discover.Config ( src/Test/Hspec/Discover/Config.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/Test/Hspec/Discover/Config.o )
    [3 of 3] Compiling Test.Hspec.Discover.Run ( src/Test/Hspec/Discover/Run.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/Test/Hspec/Discover/Run.o )
    Preprocessing executable 'hspec-discover' for hspec-discover-2.4.4..
    Building executable 'hspec-discover' for hspec-discover-2.4.4..
    [1 of 1] Compiling Main             ( driver/hspec-discover.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/hspec-discover/hspec-discover-tmp/Main.o )
    Linking .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/hspec-discover/hspec-discover ...
    /usr/bin/ld: /home/behemoth/.stack/programs/x86_64-linux/ghc-8.2.2/lib/ghc-8.2.2/rts/libHSrts.a(OSThreads.o): undefined reference to symbol 'pthread_setname_np@@GLIBC_2.12'
    //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status
    `gcc' failed in phase `Linker'. (Exit code: 1)
kevroletin commented 6 years ago

I added -threaded argument to stack configuration files, and it solved the problem for me. But I don't sure if it a good solution because I don't understand why does stack build fails and cabal build works. https://github.com/qfpl/applied-fp-course/pull/46

mankyKitty commented 6 years ago

Leaving this issue open for time being, as reference, in case others encounter the same issue.

But I will close #46 as the structure of the project has changed entirely, and travis builds the project on stack using multiple LTS versions, without error. https://travis-ci.org/qfpl/applied-fp-course

kevroletin commented 6 years ago

Ok. The latest version compiles without any problems on my machine (with stack 1.7.1).