Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pthread link errors on linux with GHC 8.2 #4130

Closed
simonmichael opened this issue Dec 7, 2017 · 15 comments
Closed

pthread link errors on linux with GHC 8.2 #4130

simonmichael opened this issue Dec 7, 2017 · 15 comments

Comments

@simonmichael
Copy link

On Ubuntu 16.04.1 LTS, stack install pandoc-2.0.4 is failing to link pthread functions:

...
[116 of 116] Compiling Text.Pandoc.App  ( src/Text/Pandoc/App.hs, .stack-work/dist/i386-linux/Cabal-2.0.1.0/build/Text/Pandoc/App.o )                                                                                                                      
    Preprocessing executable 'pandoc' for pandoc-2.0.4..                                                                                                                                                                                                       
    Building executable 'pandoc' for pandoc-2.0.4..                                                                                                                                                                                                            
    [1 of 2] Compiling Main             ( pandoc.hs, .stack-work/dist/i386-linux/Cabal-2.0.1.0/build/pandoc/pandoc-tmp/Main.o )                                                                                                                                
    [2 of 2] Compiling Paths_pandoc     ( .stack-work/dist/i386-linux/Cabal-2.0.1.0/build/pandoc/autogen/Paths_pandoc.hs, .stack-work/dist/i386-linux/Cabal-2.0.1.0/build/pandoc/pandoc-tmp/Paths_pandoc.o )                                                   
    Linking .stack-work/dist/i386-linux/Cabal-2.0.1.0/build/pandoc/pandoc ...                                                                                                                                                                                  
                                                                                                                                                                                                                                                               
    /tmp/stack14939/pandoc-2.0.4/rts/posix/OSThreads.c:137:0: error:                                                                                                                                                                                           
         error: undefined reference to 'pthread_create'                                                                                                                                                                                                        
                                                                                                                                                                                                                                                               
    /tmp/stack14939/pandoc-2.0.4/rts/posix/OSThreads.c:139:0: error:                                                                                                                                                                                           
         error: undefined reference to 'pthread_detach'                   
...

Is there an ubuntu package I'm missing ? I didn't see this error when building 1.x.

@jgm
Copy link
Owner

jgm commented Dec 7, 2017 via email

@mb21
Copy link
Collaborator

mb21 commented Dec 7, 2017

If this is this ghc bug it should be fixed in GHC 8.1

@simonmichael
Copy link
Author

This is a normal stack install, stack 1.6.1, nightly-2017-12-05 resolver, ghc 8.2.2.

@jgm
Copy link
Owner

jgm commented Dec 7, 2017 via email

@simonmichael
Copy link
Author

simonmichael commented Dec 8, 2017

More testing on this system:

stack install --resolver lts-9.17 in the pandoc source tree at 2.0.4 tag links successfully. (GHC 8.0.2)

cabal install pandoc-2.0.4 links successfully. This used the system GHC. (GHC 7.10.3)

cabal install pandoc-2.0.4 -w /home/simon/.stack/programs/i386-linux/ghc-8.2.2/bin/ghc fails with the same error. (GHC 8.2.2)

$ cabal install pandoc-2.0.4 -j -w /home/simon/.stack/programs/i386-linux/ghc-8.2.2/bin/ghc
...
Linking dist/build/pandoc/pandoc ...                                                                                                                                                 
                                                                                                                                                                                     
rts/posix/OSThreads.c:137:0: error:                                                                                                                                                  
     error: undefined reference to 'pthread_create'                                                                                                                                  
                                                                                                                                                                                     
rts/posix/OSThreads.c:139:0: error:                                                                                                                                                  
     error: undefined reference to 'pthread_detach'                                                                                                                                  
                                                                                                                                                                                     
rts/posix/OSThreads.c:141:0: error:                                                                                                                                                  
     error: undefined reference to 'pthread_setname_np'                                                                                                                              
                                                                                                                                                                                     
rts/posix/OSThreads.c:184:0: error:                                                                                                                                                  
     error: undefined reference to 'pthread_key_create'                                                                                                                              
                                                                                                                                                                                     
rts/posix/OSThreads.c:192:0: error:                                                                                                                                                  
     error: undefined reference to 'pthread_getspecific'                                                                                                                             
                                                                                                                                                                                     
rts/posix/OSThreads.c:203:0: error:                                                                                                                                                  
     error: undefined reference to 'pthread_setspecific'                                                                                                                             
                                                                                                                                                                                     
rts/posix/OSThreads.c:212:0: error:                                                                                                                                                  
     error: undefined reference to 'pthread_key_delete'                                                                                                                              
                                                                                                                                                                                     
rts/posix/OSThreads.c:371:0: error:                                                                                                                                                  
     error: undefined reference to 'pthread_kill'                                                                                                                                    
                                                                                                                                                                                     
includes/rts/OSThreads.h:59:0: error:                                                                                                                                                
     error: undefined reference to 'pthread_mutex_trylock'                                                                                                                           
collect2: error: ld returned 1 exit status                                                                                                                                           
`gcc' failed in phase `Linker'. (Exit code: 1)                                                                                                                                       
cabal: Leaving directory '/tmp/cabal-tmp-14784/pandoc-2.0.4'                                                                                                                         
cabal: Error: some packages failed to install:                                                                                                                                       
pandoc-2.0.4-3Gl6Xt4LcAi3gpzxmZMtTy failed during the building phase. The                                                                                                            
exception was:                                                                                                                                                                       
ExitFailure 1                                                                       

Following @mb21's lead: binutils on this system provides both ld and ld.gold. GHC 8.2.1 release notes say "GHC will now use ld.gold or ld.lld instead of the system’s default ld, if available. Linker availability will be evaluated at configure time. The user can manually override which linker to use by passing the LD variable to configure. You can revert to the old behavior of using the system’s default ld by passing the --disable-ld-override flag to configure."

I tried replacing /usr/bin/{gold,ld.gold} with symlinks to ld. This might not be a valid test. The format of the link error changed, but otherwise it seemed similar:

Linking .stack-work/dist/i386-linux/Cabal-2.0.1.0/build/pandoc/pandoc ...                                                                                                                                                                                                              
/usr/bin/ld.gold: /home/simon/.stack/programs/i386-linux/ghc-8.2.2/lib/ghc-8.2.2/rts/libHSrts.a(OSThreads.o): undefined reference to symbol 'pthread_create@@GLIBC_2.1'                                                                                                                
//lib/i386-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)                                                                                                                                                                                                                                         

simonmichael added a commit to simonmichael/hledger that referenced this issue Dec 8, 2017
@jgm
Copy link
Owner

jgm commented Dec 8, 2017

I tried adding -threaded to the executable stanza of cabal. Unfortunately, the travis build fails for stack + ghc 8.2.2 (looks like an out-of-memory issue compiling a dependent library). But why don't you try with the latest pull from master.

@simonmichael
Copy link
Author

@jgm: that fixed it with GHC 8.2.2 here.

@simonmichael simonmichael changed the title pthread link errors on linux pthread link errors on linux with GHC 8.2 Dec 8, 2017
@jgm
Copy link
Owner

jgm commented Dec 8, 2017

Excellent, I'll close this then.

@jgm jgm closed this as completed Dec 8, 2017
@simonmichael
Copy link
Author

Thanks for the support!

The cabal+ghc8.2 CI test probably should have failed like stack, it might need a tweak specifying GHC version.

@jgm
Copy link
Owner

jgm commented Dec 9, 2017 via email

@hanjoosten
Copy link

@jgm what exactly did you do to fix this? I am still struggling with the build of Ampersand, using pandoc 2.0.6 with ghc 8.2.2. It builds fine with cabal, but the stack build fails, even as I enabled -threaded flag.

@jgm
Copy link
Owner

jgm commented Jan 14, 2018

@hansjoosten it looks like it's pandoc-crossref that is failing in your build. Perhaps it needs the threaded flag in its cabal file? If this works, you might alert the author.

@hanjoosten
Copy link

Thanks. I guess you are right. The -threaded option was only in the executable, not with the library. I asked @lierdakil to kindly add it.

@lierdakil
Copy link
Contributor

Warning: 'ghc-options: -threaded' has no effect for libraries. It should only
be used for executables.

Did that change with GHC 8.2?

@jgm
Copy link
Owner

jgm commented Jan 16, 2018 via email

kevroletin added a commit to kevroletin/applied-fp-course that referenced this issue Mar 13, 2018
Problem:
Both stack build and stack test fail with undefined references to
pthread symbols.

Fix:
Add extra -threaded ghc option to stack configuration file.

It's unclear to me why exactly cabal build works and stack build fails.
Relevant github issues from other projects are:
jgm/pandoc#4130
commercialhaskell/stack#3807
kevroletin added a commit to kevroletin/applied-fp-course that referenced this issue Mar 13, 2018
Problem:
Both stack build and stack test fail with undefined references to
pthread symbols.

Fix:
Add extra -threaded ghc option to stack configuration file.

It's unclear to me why exactly cabal build works and stack build fails.
Relevant github issues from other projects are:
jgm/pandoc#4130
commercialhaskell/stack#3807
kevroletin added a commit to kevroletin/applied-fp-course that referenced this issue Mar 13, 2018
Problem:
Both stack build and stack test fail with undefined references to
pthread symbols.

Fix:
Add extra -threaded ghc option to stack configuration file.

It's unclear to me why exactly cabal build works and stack build fails.
Relevant github issues from other projects are:
jgm/pandoc#4130
commercialhaskell/stack#3807
kevroletin added a commit to kevroletin/applied-fp-course that referenced this issue Mar 13, 2018
Problem:
Both stack build and stack test fail with undefined references to
pthread symbols.

Fix:
Add extra -threaded ghc option to stack configuration file.

It's unclear to me why exactly cabal build works and stack build fails.
Relevant github issues from other projects are:
jgm/pandoc#4130
commercialhaskell/stack#3807
danse added a commit to italia/pandoc that referenced this issue Apr 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants