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

installing older Ruby versions on OSX after XCode 12 #1489

Closed
eddroid opened this issue Nov 11, 2020 · 20 comments
Closed

installing older Ruby versions on OSX after XCode 12 #1489

eddroid opened this issue Nov 11, 2020 · 20 comments

Comments

@eddroid
Copy link

eddroid commented Nov 11, 2020

tldr: This is an installation problem and solution. Maybe ya'll can do something about this in ruby-build itself? Maybe not. In any case, it's here for the search bots.

Problem

$ rbenv install 2.1.7

output

BUILD FAILED (Mac OS X 10.15.7 using ruby-build 20200926)

Inspect or clean up the working tree at /var/folders/hk/6ghd603s4gggg2kpspf5jjth0000gn/T/ruby-build.20201110215242.31778.FSCdTL
Results logged to /var/folders/hk/6ghd603s4gggg2kpspf5jjth0000gn/T/ruby-build.20201110215242.31778.log

end of logfile output

# ruby-build.20201110215242.31778.log

3 warnings and 4 errors generated.
make[2]: *** [ossl_pkcs7.o] Error 1
make[1]: *** [ext/openssl/all] Error 2
make[1]: *** Waiting for unfinished jobs....
compiling objspace_dump.c
installing default objspace libraries
linking shared-object objspace.bundle
linking shared-object nkf.bundle
13 warnings generated.
linking shared-object date_core.bundle
make: *** [build-ext] Error 2

sample line from openssl extension MakeMakefile log:

# <BUILD_DIR>/ruby-2.1.7/ext/openssl/mkmf.log 
conftest.c:13:15: error: implicit declaration of function 'OPENSSL_cleanse' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

Solution

$ CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.1.7

output:

Downloading openssl-1.0.2u.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16
Installing openssl-1.0.2u...
Installed openssl-1.0.2u to /Users/***/.rbenv/versions/2.1.7

Downloading ruby-2.1.7.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.7.tar.bz2
Installing ruby-2.1.7...

WARNING: ruby-2.1.7 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.

ruby-build: using readline from homebrew
Installed ruby-2.1.7 to /Users/***/.rbenv/versions/2.1.7

Explanation

XCode 12 was released September 16, 2020. Apple changed the default CFLAGS for clang.

Clang now reports an error when you use a function without an explicit declaration when building C or Objective-C code for macOS (-Werror=implicit-function-declaration flag is on).

This change prevents this version of Ruby (and possibly others) from compiling native extensions like openssl and zlib. Unfortunately, those errors only appear in the corresponding mkmf.log for the extensions.

This could also affect building some gems that use C code.

gem install <GEMNAME> -- --with-cflags="-Wno-error=implicit-function-declaration"
@hsbt hsbt transferred this issue from rbenv/rbenv Nov 11, 2020
@coding-bunny
Copy link

Re: This could also affect building some gems that use C code.

I can say this already affects the mysql2 gem....

@fladson
Copy link

fladson commented Dec 30, 2020

Thank you @eddroid for taking the time to write this up, I tried a lot of options and this was the only one that solved for me.

@xvrdmng
Copy link

xvrdmng commented Apr 7, 2021

Thanks for the solution!

@hsbt hsbt pinned this issue Apr 15, 2021
@hsbt
Copy link
Member

hsbt commented Apr 15, 2021

I pinned this to top of issue pages.

@normanrs
Copy link

Not sure why discussion of installing 2.6.7 is closed. I am having issues installing it via ruby-install 2.6.7 and even after setting the CFLAGS variable chruby doesn't recognize it.

@mislav
Copy link
Member

mislav commented May 20, 2021

@normanrs ruby-install is a different project than ours: https://github.com/postmodern/ruby-install

@YudaiImazu

This comment has been minimized.

@krsinghshubham
Copy link

krsinghshubham commented Jun 2, 2021

To install rvm try these commands in order:

\curl -sSL https://get.rvm.io | bash
source /Users/sansekar/.rvm/scripts/rvm
rvm pkg install openssl
rvm install ruby-2.3.2 --with-openssl-dir=$HOME/.rvm/usr

@eddroid
Copy link
Author

eddroid commented Jun 2, 2021

@YudaiImazu I can't tell if your error is related to this issue. Your log only shows warnings and notes. Upload the full log into a public gist (or something like that). It's unclear if you set the CFLAGS as described in this issue.

CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.3.2

@YudaiImazu

This comment has been minimized.

@YudaiImazu
Copy link

@eddroid @krsinghshubham
Thank you for helping me.
I couldn't solve this problem by setting the CFLAGS.

Above is my log.

Your reply would be appreciated.
Thank you in advance.

@eddroid
Copy link
Author

eddroid commented Jun 3, 2021

Please move your log output to a gist. While logged-in to GitHub, visit https://gist.github.com/ and paste your log output into there. Save it as a public gist. Then update your comment to link to your log instead of pasting the contents into a comment.

Your error isn't related to this issue. Searching for "error:", it seems to be related to X11, which is probably a problem with your version of XCode. You should create a new issue for that.

@mnishiguchi
Copy link

Today I had a similar issue on my MacBook Pro.

MacOS Big Sur Version 11.4
MacBook Pro (13-inch, 2018, Four Thunderbolt 3 Ports)

After trial and error, the following worked.

# Ruby version that I want to install
RUBY_VERSION=2.2.10

# Install that Ruby version using rbenv
CFLAGS="-Wno-error=implicit-function-declaration" \
LDFLAGS="-L$HOME/.rbenv/versions/$RUBY_VERSION/lib -L/usr/local/opt/readline/lib -L$(brew --prefix openssl@1.0)/lib" \
CPPFLAGS="-I$HOME/.rbenv/versions/$RUBY_VERSION/include -I/usr/local/opt/readline/include -I$(brew --prefix openssl@1.0)/include" \
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" \
rbenv install $RUBY_VERSION

I hope this will help somebody.

@jrochkind
Copy link

jrochkind commented Jul 13, 2021

Could an admin please delete the comment at #1489 (comment) -- it makes this issue very hard to read to the bottom, and this issue is kind of important to be easily readable, it seems to be affecting a lot of people trying to use ruby-build on latest XCode/MacOS? (I don't really understand why the issue is closed)

@YudaiImazu it is rude to paste in that many lines to a github issue comment.

@xuanchien
Copy link

None of the above solutions worked for me. I met this issue on Mac Big Sur when trying to install Ruby 2.6.5. The error log shows error messages like this

In file included from mjit_compile.c:133:
./mjit_compile.inc:295:70: error: expected ')'
        fprintf(f, "    const rb_serial_t ic_serial = (rb_serial_t)%"PRI_SERIALT_PREFIX"u;\n", ic_copy->ic_serial);
               

I suspected the Clang compiler was the issue but I could not found any solution on the internet. In the end, I could fix this issue by doing the following steps:

brew install gcc

Brew would not automatically link this gcc because it's conflicting with the default c++ path. You would see something like this

The formula built, but is not symlinked into /usr/local
Could not symlink include/c++
Target /usr/local/include/c++
already exists. You may want to remove it:
  rm '/usr/local/include/c++'

To force the link and overwrite all conflicting files:
  brew link --overwrite gcc

To list all files that would be deleted:
  brew link --overwrite --dry-run gcc

Possible conflicting files are:
/usr/local/include/c++ -> /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c+

I decided to force the link and overwrite all conflicting files (hopefully it won't affect other parts in your system, BE careful when doing this):

brew link --overwrite gcc

I also created a symlink to the new gcc

ln -s /usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11 /usr/local/lib/gcc/11

Then I run the command

CC=/usr/local/Cellar/gcc/11.1.0_1/bin/gcc rbenv install 2.6.5

And finally I got Ruby 2.6.5 installed as expected. Hopefully it could help people with similar issue like me.

@namratasaun
Copy link

Ruby version that I want to install

RUBY_VERSION=2.2.10

Install that Ruby version using rbenv

CFLAGS="-Wno-error=implicit-function-declaration"
LDFLAGS="-L$HOME/.rbenv/versions/$RUBY_VERSION/lib -L/usr/local/opt/readline/lib -L$(brew --prefix openssl@1.0)/lib"
CPPFLAGS="-I$HOME/.rbenv/versions/$RUBY_VERSION/include -I/usr/local/opt/readline/include -I$(brew --prefix openssl@1.0)/include"
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)"
rbenv install $RUBY_VERSION

image

getting this error

I have MacOS 11.5.1

kimuraw added a commit to macports/macports-ports that referenced this issue Oct 13, 2021
closes: https://trac.macports.org/ticket/62500

see: rbenv/ruby-build#1489

conftest from ext/openssl/extconf.rb runs without including <openssl/*.h>.
this leads conflicts between ext/openssl/extconf.h and ext/openssl/*.[hc]
under "-Werror=implicit-function-declaration", default with recent Xcode.

ext/openssl/mkmf.log:
{{{
have_func: checking for HMAC_CTX_copy()... -------------------- yes  #### <= returns "no" under -Werror=implicit-function-declaration

"/usr/bin/clang -o conftest -I../../.ext/include/x86_64-darwin20 -I../.././include -I../.././ext/openssl  -I/opt/local/include/openssl-1.0 -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -pipe -Os -Wno-error=implicit-function-declaration -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -fno-common  conftest.c  -L/opt/local/lib/openssl-1.0 -L/opt/local/lib -L. -L../.. -L. -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -fstack-protector -L/opt/local/lib  -L/opt/local/lib   -arch x86_64   -lssl -lcrypto -lruby.2.2.0-static -framework CoreFoundation  -lssl -lcrypto -lpthread -ldl -lobjc "
conftest.c:13:57: error: use of undeclared identifier 'HMAC_CTX_copy'
int t(void) { void ((*volatile p)()); p = (void ((*)()))HMAC_CTX_copy; return 0; }
    ¦   ¦   ¦   ¦   ¦   ¦   ¦   ¦   ¦   ¦               ^
1 error generated.
checked program was:
/* begin */
 1: #include "ruby.h"  #### <= includes only ruby.h
 2:-
 3: /*top*/
 4: extern int t(void);
 5: int main(int argc, char **argv)
 6: {
 7:   if (argc > 1000000) {
 8:     printf("%p", &t);
 9:   }
10:-
11:   return 0;
12: }
13: int t(void) { void ((*volatile p)()); p = (void ((*)()))HMAC_CTX_copy; return 0; }
/* end */
}}}
@mirageglobe
Copy link

mirageglobe commented Oct 15, 2021

this may help someone as I had the same issue and the solution was using a version of bison at 2.7.

https://stackoverflow.com/questions/69394316/ruby-install-fails-when-installing-ruby-2-6-x-and-3-0-x-on-mac-osx-11-6/69394317#69394317

@tamphh
Copy link

tamphh commented Dec 6, 2021

My colleague helped me solving this problem with script below:

#!/usr/bin/env bash

set -e

# ruby-install --latest

OPENSSL_VERSION=1.1
OPENSSL_DIR=/usr/local/opt/openssl@${OPENSSL_VERSION}

function install-ruby-on-mac() {
    PKG_CONFIG_PATH=${OPENSSL_DIR}/lib/pkgconfig \
    ruby-install $(ruby-install-options $1) \
        ruby $1 \
        -- \
        --with-openssl-dir=${OPENSSL_DIR} \
        --with-opt-dir=$(brew --prefix readline) \
        --without-tcl --without-tk
}
install-ruby-on-mac 2.5.8
install-ruby-on-mac 2.6.8
install-ruby-on-mac 2.7.4

Hope it could help someone.

@hsbt hsbt unpinned this issue Dec 26, 2021
@SummitPatel
Copy link

Today I had a similar issue on my MacBook Pro.

MacOS Big Sur Version 11.4
MacBook Pro (13-inch, 2018, Four Thunderbolt 3 Ports)

After trial and error, the following worked.

# Ruby version that I want to install
RUBY_VERSION=2.2.10

# Install that Ruby version using rbenv
CFLAGS="-Wno-error=implicit-function-declaration" \
LDFLAGS="-L$HOME/.rbenv/versions/$RUBY_VERSION/lib -L/usr/local/opt/readline/lib -L$(brew --prefix openssl@1.0)/lib" \
CPPFLAGS="-I$HOME/.rbenv/versions/$RUBY_VERSION/include -I/usr/local/opt/readline/include -I$(brew --prefix openssl@1.0)/include" \
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" \
rbenv install $RUBY_VERSION

I hope this will help somebody.

This helped solved my issue installing ruby 2.7.3 after upgrading from Catalina to Big Sur. Thanks!

@nkoppala-facilgo
Copy link

Am trying to install Ruby 2.6.7 in mac os using command CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.6.7 but getting below error

`Inspect or clean up the working tree at /var/folders/p8/201hwbjx705fb0by88b64p0r0000gn/T/ruby-build.20230830182044.29712.aSTvUf
Results logged to /var/folders/p8/201hwbjx705fb0by88b64p0r0000gn/T/ruby-build.20230830182044.29712.log

Last 10 log lines:
imemo_type_ids[10] = rb_intern("imemo_parser_strterm");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../.././include/ruby/ruby.h:1826:56: note: expanded from macro 'rb_intern'
extension (RUBY_CONST_ID_CACHE((ID), (str))) :
^
`

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