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

Issue in Makefile of Haskell parser #427

Closed
daneshvar-amrollahi opened this issue Oct 29, 2022 · 6 comments
Closed

Issue in Makefile of Haskell parser #427

daneshvar-amrollahi opened this issue Oct 29, 2022 · 6 comments
Labels

Comments

@daneshvar-amrollahi
Copy link

Hi,

I was executing the Mini tutorial in the README and I faced a linking error related to pthread as followed:

$ bnfc -d -m Sum.cf
2 rules accepted

Use Alex 3 to compile Sum/Lex.x.
writing new file ./Sum/Abs.hs
writing new file ./Sum/Print.hs
writing new file ./Sum/Lex.x
writing new file ./Sum/Par.y
writing new file ./Sum/Test.hs
writing new file ./Sum/ErrM.hs
writing new file ./Sum/Skel.hs
writing new file ./Sum/Doc.txt
writing new file ./Makefile


$ make
alex --ghc Sum/Lex.x
happy --array --info --ghc --coerce Sum/Par.y
Grammar info written to: Sum/Par.info
ghc  Sum/Test
[1 of 7] Compiling Sum.Abs          ( Sum/Abs.hs, Sum/Abs.o )
[2 of 7] Compiling Sum.Lex          ( Sum/Lex.hs, Sum/Lex.o )
[3 of 7] Compiling Sum.Par          ( Sum/Par.hs, Sum/Par.o )
[4 of 7] Compiling Sum.Print        ( Sum/Print.hs, Sum/Print.o )
[5 of 7] Compiling Sum.Skel         ( Sum/Skel.hs, Sum/Skel.o )
[6 of 7] Compiling Main             ( Sum/Test.hs, Sum/Test.o )
[7 of 7] Linking Sum/Test

rts/posix/ticker/Pthread.c:214:0: error:
     error: undefined reference to 'pthread_sigmask'

rts/posix/ticker/Pthread.c:216:0: error:
     error: undefined reference to 'pthread_create'

rts/posix/ticker/Pthread.c:226:0: error:
     error: undefined reference to 'pthread_setname_np'

rts/posix/ticker/Pthread.c:219:0: error:
     error: undefined reference to 'pthread_sigmask'

rts/posix/ticker/Pthread.c:266:0: error:
     error: undefined reference to 'pthread_join'

rts/posix/ticker/Pthread.c:272:0: error:
     error: undefined reference to 'pthread_detach'

rts/posix/OSMem.c:570:0: error:
     error: undefined reference to 'pthread_attr_getstacksize'

rts/posix/OSThreads.c:114:0: error:
     error: undefined reference to 'pthread_condattr_setclock'

rts/posix/OSThreads.c:193:0: error:
     error: undefined reference to 'pthread_create'

rts/posix/OSThreads.c:195:0: error:
     error: undefined reference to 'pthread_detach'

rts/posix/OSThreads.c:199:0: error:
     error: undefined reference to 'pthread_setname_np'

rts/posix/OSThreads.c:246:0: error:
     error: undefined reference to 'pthread_key_create'

rts/posix/OSThreads.c:265:0: error:
     error: undefined reference to 'pthread_setspecific'

rts/posix/OSThreads.c:274:0: error:
     error: undefined reference to 'pthread_key_delete'

rts/posix/OSThreads.c:475:0: error:
     error: undefined reference to 'pthread_join'

rts/posix/OSThreads.c:254:0: error:
     error: undefined reference to 'pthread_getspecific'

rts/posix/OSThreads.c:469:0: error:
     error: undefined reference to 'pthread_kill'

rts/include/rts/OSThreads.h:69:0: error:
     error: undefined reference to 'pthread_mutex_trylock'
collect2: error: ld returned 1 exit status
ghc-9.4.2: `gcc' failed in phase `Linker'. (Exit code: 1)
make: *** [Makefile:31: Sum/Test] Error 1

The error is raising from this line of the Makefile: ${GHC} ${GHC_OPTS} $@

It needs a -lpthread to be fixed. I will soon open a pull request to fix this.

daneshvar-amrollahi added a commit to daneshvar-amrollahi/bnfc that referenced this issue Oct 29, 2022
@andreasabel
Copy link
Member

Thanks for the report! Can you provide some info about your OS and happy and alex versions? GHC is 9.4.2, as I can see.

@andreasabel andreasabel added Haskell Makefile Concerning the generated Makefile labels Oct 31, 2022
@andreasabel andreasabel linked a pull request Oct 31, 2022 that will close this issue
@daneshvar-amrollahi
Copy link
Author

Thanks for the report! Can you provide some info about your OS and happy and alex versions? GHC is 9.4.2, as I can see.

The OS is Ubuntu 20.04.4 LTS. Here is the info on alex and happy:

$ alex --version
Alex version 3.2.7.1, (c) 2003 Chris Dornan and Simon Marlow
$ happy --version
Happy Version 1.20.0 Copyright (c) 1993-1996 Andy Gill, Simon Marlow (c) 1997-2005 Simon Marlow

Happy is a Yacc for Haskell, and comes with ABSOLUTELY NO WARRANTY.
This program is free software; you can redistribute it and/or modify
it under the terms given in the file 'LICENSE' distributed with
the Happy sources.

@andreasabel
Copy link
Member

These are the latest version of happy and alex.
On my system (macOS Mojave) no special flag -lpthread is needed, but it also does not harm.
I'd like some more evidence though that the addition is portable (Windows and other common OSs).
Note that one can always pass in extra flags via:

make GHC_OPTS='-lpthread'...

@andreasabel
Copy link
Member

andreasabel commented Oct 31, 2022

These are old issues I found on the topic, but this was GHC 8.2:

There is an open GHC issue but this displays different symptoms:

daneshvar-amrollahi added a commit to daneshvar-amrollahi/bnfc that referenced this issue Oct 31, 2022
@daneshvar-amrollahi
Copy link
Author

These are the latest version of happy and alex. On my system (macOS Mojave) no special flag -lpthread is needed, but it also does not harm. I'd like some more evidence though that the addition is portable (Windows and other common OSs). Note that one can always pass in extra flags via:

make GHC_OPTS='-lpthread'...

In Windows, Makefiles are usually setup using tools like MinGw and Cygwin, which allows users to install a bunch of unix-based programs. I guess it should be compatible with the makefiles working on Linux.

@andreasabel
Copy link
Member

Thanks, @daneshvar-amrollahi for your report and efforts. I still remain unconvinced that this is a general problem (rather than something on your machine, maybe). If this was a common problem, one of my students in my course using BNFC would have had it and alerted me, I suppose. Also, having to pass extra -l flags to GHC is something you usually don't have to do.
Thus, I am closing this issue for now, waiting for more evidence. Please use the workaround I describe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants