Bug #18019
closed3.0.X fails to link on Mac OS X 10.15.7 due to linker error related to _coroutine_transfer
Description
I'm struggling with building ruby 3.0.X on my Mac Catalina (Intel based). Please note all 2.X versions are compiling correctly.
I've already tried to use gnugcc but getting same error:
▶ gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin ▶ g++ --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin Linker command fails on (full log attached):
+ clang -fdeclspec -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -std=gnu99 -pipe -L. -fstack-protector-strong -L/usr/local/lib -fstack-protector-strong -Wl,-pie -framework Security -framework Foundation main.o dmydln.o miniinit.o dmyext.o array.o ast.o bignum.o class.o compar.o compile.o complex.o cont.o debug.o debug_counter.o dir.o dln_find.o encoding.o enum.o enumerator.o error.o eval.o file.o gc.o hash.o inits.o io.o iseq.o load.o marshal.o math.o memory_view.o mjit.o mjit_compile.o node.o numeric.o object.o pack.o parse.o proc.o process.o ractor.o random.o range.o rational.o re.o regcomp.o regenc.o regerror.o regexec.o regparse.o regsyntax.o ruby.o scheduler.o signal.o sprintf.o st.o strftime.o string.o struct.o symbol.o thread.o time.o transcode.o transient_heap.o util.o variable.o version.o vm.o vm_backtrace.o vm_dump.o vm_sync.o vm_trace.o coroutine/amd64/Context.o enc/ascii.o enc/us_ascii.o enc/unicode.o enc/utf_8.o enc/trans/newline.o explicit_bzero.o setproctitle.o addr2line.o -lpthread -lgmp -ldl -lobjc -o miniruby Undefined symbols for architecture x86_64: "_coroutine_transfer", referenced from: _fiber_setcontext in cont.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [miniruby] Error 1 Some people reported the same issue with Catalina and Big Sur: https://github.com/rbenv/ruby-build/issues/1723#issuecomment-872548168
Command Line Tools SDKs:
▶ ls /Library/Developer/CommandLineTools/SDKs/ 14 13 Feb 13:12 MacOSX.sdk -> MacOSX11.1.sdk 9 Jul 2020 MacOSX10.15.sdk 30 Nov 2020 MacOSX11.1.sdk I have very basic understanding of C and I'm suspecting that removal of this macro can be causing this behaviour: https://git.ruby-lang.org/ruby.git/commit/?id=e0f0ab959e , but I'm more than happy to be proven wrong
Files
Updated by xtkoba (Tee KOBAYASHI) over 4 years ago
It seems that the configure variable rb_cv_symbol_prefix is not set correctly:
checking for prefix of external symbols... gnm: conftest.o: unknown load command 0x32 A workaround would be to manually specify its value such as:
./configure rb_cv_symbol_prefix=_
Updated by mic-kul (Michal Kulesza) over 4 years ago
- File full-error.log full-error.log added
Thanks @xtkoba.
I've tried this and now it fails on compiling bigdecimal:
compiling bigdecimal.c In file included from bigdecimal.c:13: ./bigdecimal.h:122:1: error: redefinition of 'rb_array_const_ptr' rb_array_const_ptr(VALUE a) ^ ../.././include/ruby/internal/core/rarray.h:184:1: note: previous definition is here rb_array_const_ptr(VALUE a) ^ In file included from bigdecimal.c:13: ./bigdecimal.h:139:1: error: static declaration of 'rb_sym2str' follows non-static declaration rb_sym2str(VALUE sym) ^ ../.././include/ruby/internal/symbol.h:63:7: note: previous declaration is here VALUE rb_sym2str(VALUE); ^ bigdecimal.c:108:1: error: static declaration of 'rb_rational_num' follows non-static declaration rb_rational_num(VALUE rat) ^ ../.././include/ruby/internal/intern/rational.h:39:7: note: previous declaration is here VALUE rb_rational_num(VALUE rat); ^ bigdecimal.c:120:1: error: static declaration of 'rb_rational_den' follows non-static declaration rb_rational_den(VALUE rat) ^ ../.././include/ruby/internal/intern/rational.h:40:7: note: previous declaration is here VALUE rb_rational_den(VALUE rat); ^ bigdecimal.c:132:1: error: static declaration of 'rb_complex_real' follows non-static declaration rb_complex_real(VALUE cmp) ^ ../.././include/ruby/internal/intern/complex.h:38:7: note: previous declaration is here VALUE rb_complex_real(VALUE z); ^ bigdecimal.c:144:1: error: static declaration of 'rb_complex_imag' follows non-static declaration rb_complex_imag(VALUE cmp) ^ ../.././include/ruby/internal/intern/complex.h:39:7: note: previous declaration is here VALUE rb_complex_imag(VALUE z); ^ 6 errors generated. make[2]: *** [bigdecimal.o] Error 1 make[1]: *** [ext/bigdecimal/all] Error 2 make: *** [build-ext] Error 2
Updated by xtkoba (Tee KOBAYASHI) over 4 years ago
The content of ext/bigdecimal/mkmf.log in the build directory might help. But before seeing it I guess that something is wrong with your binutils (gnm, gar, ...) as I see the following message in the attached log:
linking static-library libruby.3.0-static.a gar: dln.o: unknown load command 0x32 Googling with "unknown load command 0x32" I found an issue in binutils Bugzilla [1] which implies that this issue should be fixed in newer versions.
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=23728
Note that the configure script by default prefers g-prefixed version of binutils tools, and so gnm and gar are used when they are available instead of nm and ar which should come with Apple's Xcode distribution. To use non g-prefixed version you can specify NM and AR (and other tools if necessary) such as:
./configure NM=nm AR=ar
Updated by mic-kul (Michal Kulesza) over 4 years ago
Ah yes, that was it!
I had binutils 2.30 installed. After updating it to 2.36.1 everything compiles properly now!
Thank you!
Updated by jeremyevans0 (Jeremy Evans) over 4 years ago
- Status changed from Open to Closed
Updated by mame (Yusuke Endoh) over 3 years ago
- Related to Bug #18745: build ruby3.0.4 fail on macOS 12.3.1 monterey fail (Apple silicon arm64) added