ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.71k stars 415 forks source link

gmake fails on FreeBSD #2105

Closed tschuxxi closed 7 years ago

tschuxxi commented 7 years ago

Hi,

i tried to to build ponyc like described in the readme for FreeBSD but I always get the following error message:

Linking libponyrt.tests
build/release/libponyrt.a(threads.o): In function `ponyint_thread_create':
src/libponyrt/platform/threads.c:(.text+0xd): undefined reference to `pthread_create'
c++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake: *** [Makefile:697: build/release/libponyrt.tests] Fehler 1

I'm running 11.1-RELEASE FreeBSD 11.1-RELEASE with GNU Make 4.2.1

dipinhora commented 7 years ago

@tschuxxi I think we might need to use -pthread instead of -lpthread as an argument to gcc (see https://stackoverflow.com/a/23251828 and https://groups.google.com/forum/#!topic/comp.programming.threads/NCEpG0EOCCY).

Can you try changing the makefile line 352 (https://github.com/ponylang/ponyc/blob/master/Makefile#L352) from:

  llvm.libs += -lpthread -lexecinfo

to:

  llvm.libs += -pthread -lexecinfo

and line 287 in genexe.c (https://github.com/ponylang/ponyc/blob/master/src/libponyc/codegen/genexe.c#L287) from:

    "%s %s %s %s -lpthread %s -lm %s",

to

    "%s %s %s %s -pthread %s -lm %s",

and then compiling to see if it works?

SeanTAllen commented 7 years ago

@tschuxxi if you can verify this as a fix and get it in soon (next hour or so) it can make it into the 0.16.1 release I am doing soon.

tschuxxi commented 7 years ago

I changed the files but still get the same error message

dipinhora commented 7 years ago

@tschuxxi Thanks for trying and confirming that fix didn't work.

The following makefile fix should resolve the issue (I did a quick test via vagrant):

diff --git a/Makefile b/Makefile
index a20c48fa..abe47cc4 100644
--- a/Makefile
+++ b/Makefile
@@ -465,6 +465,8 @@ ifeq ($(OSTYPE),linux)
 endif

 ifeq ($(OSTYPE),freebsd)
+  libponyc.tests.links += libpthread
+  libponyrt.tests.links += libpthread
   libponyc.benchmarks.links += libpthread
   libponyrt.benchmarks.links += libpthread
 endif

The issue was that when linking tests on freebsd, we should be including libpthread or else symbol resolution for pthread functions doesn't work.

If would be ideal if you can confirm the fix and then we can try and get it into the release for 0.16.1 that @SeanTAllen is doing soon.