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

gcc does not support "-Wno-error=shorten-64-to-32" #325

Closed
quark-zju opened this issue Mar 10, 2013 · 19 comments · Fixed by #339
Closed

gcc does not support "-Wno-error=shorten-64-to-32" #325

quark-zju opened this issue Mar 10, 2013 · 19 comments · Fixed by #339

Comments

@quark-zju
Copy link
Contributor

ruby-build script contains following workaround for clang:

# Work around warnings building Ruby 2.0 on Clang 2.x
if type clang &>/dev/null; then
  if "${CC:-clang}" -x c /dev/null -E -Wno-error=shorten-64-to-32 &>/dev/null; then
    RUBY_CFLAGS="$RUBY_CFLAGS -Wno-error=shorten-64-to-32"
  fi
fi

If both gcc and clang installed and cc is gcc, the above workaround will be triggered wrongly and result in failing to compile anything:

configure:3741: checking whether the C compiler works
configure:3763: gcc   -Wno-error=shorten-64-to-32 -I'/home/quark/.rbenv/versions/2.0.0-p0/include'  -L'/home/quark/.rbenv/versions/2.0.0-p0/lib'  conftest.c  >&5
cc1: error: -Werror=shorten-64-to-32: no option -Wshorten-64-to-32
configure:3767: $? = 1
configure:3805: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define CANONICALIZATION_FOR_MATHN 1
| #define RUBY_BASE_NAME "ruby" !<verconf>!
| #define RUBY_VERSION_NAME RUBY_BASE_NAME"-"RUBY_LIB_VERSION !<verconf>!
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:3810: error: in `/tmp/ruby-build.20130310154119.10022/ruby-2.0.0-p0':
configure:3812: error: C compiler cannot create executables
See `config.log' for more details

How about changing ${CC:-clang} to ${CC:-cc} in the workaround script?

@lpar
Copy link

lpar commented Mar 14, 2013

You don't even need to have clang installed to get the problem. I hit it on Debian Stable with only GCC installed, so somehow the "type clang" stuff is being triggered even when the compiler is GCC. Nasty.

@Ivoz
Copy link

Ivoz commented Mar 15, 2013

In short, this is a clang-specific flag; it should only be added if clang is the compiler being used, not universally. This check should be done after we know which compiler is being used.

@alexspeller
Copy link

I was just hit by this and spent about 6 hours uninstalling and reinstalling my toolchain because I thought that was the problem. I am an idiot :(

@quark-zju
Copy link
Contributor Author

This is duplicated with #319.

gnprice added a commit to gnprice/ruby-build that referenced this issue Apr 2, 2013
The previous version of this logic was causing us to
pass the flag when
 * clang is on the PATH, and
 * $CC, or 'clang' if CC unset, accepts the flag.
But this is totally wrong if we have clang installed,
haven't set $CC, and are going to end up using gcc.
We end up passing the flag to gcc, which rejects it.

The real fix is to put this in the autoconf goo in MRI
upstream -- the only correct way to decide whether to pass
this flag is after we know exactly what compiler we're using
and can test if that compiler accepts the flag.  But we can
do better than before by approximating autoconf's choice of
compiler as $CC if set, 'cc' otherwise (which will typically
be a symlink to gcc or clang or another.)

Fixes: rbenv#325
gnprice added a commit to gnprice/ruby-build that referenced this issue Apr 2, 2013
The previous version of this logic was causing us to
pass the flag when
 * clang is on the PATH, and
 * $CC, or 'clang' if CC unset, accepts the flag.
But this is totally wrong if we have clang installed,
haven't set $CC, and are going to end up using gcc.
We end up passing the flag to gcc, which rejects it.

The real fix is to put this in the autoconf goo in MRI
upstream -- the only correct way to decide whether to pass
this flag is after we know exactly what compiler we're using
and can test if that compiler accepts the flag.  But we can
do better than before by approximating autoconf's choice of
compiler as $CC if set, 'cc' otherwise (which will typically
be a symlink to gcc or clang or another.)

Fixes: rbenv#319
  and rbenv#325, which is a dupe.
@jeremy
Copy link
Member

jeremy commented Apr 26, 2013

Fixed by #339

@stantona
Copy link

@mislav
Copy link
Member

mislav commented Jun 1, 2014

@stantona: Compiling Nokogiri is different than compiling Ruby. This project only deals with producing working Ruby installations. For compiling Nokogiri please see its troubleshooting docs to see if there are extra steps to install the gem on your system.

@markjreed
Copy link

Still seeing this issue trying to build 1.9.3 on Yosemite. The check in the ruby-build script assumes that the compiler used will be either cc or $CC, but if $CC is not set, the ruby 1.9.3 configure script will explicitly look for gcc and use that instead, causing a mismatch. Had to explicitly set CC=gcc purely for ruby-build's benefit, even though the ruby distro builds fine on its own without it.

@lpar
Copy link

lpar commented Oct 21, 2014

1.9.3 is EOL in March, just FYI. If you're still building it for some reason, you might want to stop.

@markjreed
Copy link

Thanks, Ipar. Unfortunately, I still have to support systems that still depend on Ruby 1.9 (and break on 2.x), so it's convenient to be able to use rbenv to switch to 1.9 locally on my Mac as well. (We have a team working on replacing these systems and updating the things that depend on them, but can't spend too many resources on that effort, so it's going slowly, and meanwhile we still have to keep them running.)

@rmehner
Copy link

rmehner commented Oct 26, 2014

@lpar this happens with newer versions like 2.2.0-preview1 as well.

$CC is not set, both clang && gcc are installed, the latter one is linked to clang. Ruby's ./configure seems to pick up gcc (explained by @gnprice right here #319 (comment)), while ruby-build sets that CFLAG. Result:

$ rbenv install 2.2.0-preview1
[...]
checking whether CFLAGS is valid... no
configure: error: something wrong with CFLAGS=" -O3 -Wno-error=shorten-64-to-32  "
make: *** No targets specified and no makefile found.  Stop.

Workaround is to explicitly set $CC to either clang or gcc, like CC=clang rbenv install 2.2.0-preview1

A solution might be that ruby-build exports CC to a known value, like it does when you use require_gcc, but I'm not sure what side effects that might have.

@rmehner
Copy link

rmehner commented Oct 26, 2014

Turns out this is a known issue tracked in #651, which happens if you have apple-gcc4.2 installed as well on Yosemite.

@Nakilon
Copy link

Nakilon commented Oct 11, 2015

Despite this issue is a year old I had to do this patch manually a month ago.

$ ruby-build --version
ruby-build 20150818

@mislav
Copy link
Member

mislav commented Oct 11, 2015

@Nakilon That's strange. This is what ruby-build has right now:

if "${CC:-cc}" -x c /dev/null -E -Wno-error=shorten-64-to-32 &>/dev/null; then
  RUBY_CFLAGS="-O3 -Wno-error=shorten-64-to-32 $RUBY_CFLAGS"
fi

What state was your file in, and what did you have to remove?

@lacostenycoder
Copy link

I'm now having this issue, bundle install fails.

current directory: /Users/lancejordan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/unf_ext-0.0.7.1/ext/unf_ext
/Users/lancejordan/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20151230-25006-12oc2t3.rb extconf.rb
checking for main() in -lstdc++... yes
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/lancejordan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-13/2.3.0-static/unf_ext-0.0.7.1/mkmf.log

current directory: /Users/lancejordan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/unf_ext-0.0.7.1/ext/unf_ext
make "DESTDIR=" clean

current directory: /Users/lancejordan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/unf_ext-0.0.7.1/ext/unf_ext
make "DESTDIR="
compiling unf.cc
g++: error: unrecognized command line option ‘-Wshorten-64-to-32’
g++: error: unrecognized command line option ‘-Wdivision-by-zero’
g++: error: unrecognized command line option ‘-Wextra-tokens’
make: *** [unf.o] Error 1

make failed, exit code 2

and

current directory: /Users/lancejordan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/eventmachine-1.0.7/ext
/Users/lancejordan/.rbenv/versions/2.3.0/bin/ruby -r ./siteconf20151230-25006-1kq1ce.rb extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... no
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_thread_fd_select()... yes
checking for rb_fdset_t in ruby/intern.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... no
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue.h... yes
checking for clock_gettime()... no
checking for gethrtime()... no
creating Makefile

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/lancejordan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-13/2.3.0-static/eventmachine-1.0.7/mkmf.log

current directory: /Users/lancejordan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/eventmachine-1.0.7/ext
make "DESTDIR=" clean

current directory: /Users/lancejordan/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/eventmachine-1.0.7/ext
make "DESTDIR="
compiling binder.cpp
g++: error: unrecognized command line option ‘-Wshorten-64-to-32’
g++: error: unrecognized command line option ‘-Wdivision-by-zero’
g++: error: unrecognized command line option ‘-Wextra-tokens’
make: *** [binder.o] Error 1

make failed, exit code 2

@glaszig
Copy link

glaszig commented May 4, 2016

@lacostenycoder did you find a solution for the unf_ext compilation error?

@NuLL3rr0r
Copy link

@lacostenycoder did you find a solution for the unf_ext compilation error?

I'm on FreeBSD and I have the same issue when I have gcc and clang installed at the same time. The default compiler is clang. Even explicitly setting CC to clang gives the same results:

$ CC=clang RUBY_CONFIGURE_OPTS=--with-opt-dir=/usr/local ruby-build 2.3.1 ~/.rubies/ruby-2.3.1
$ cd ~/discourse
$ bundle install --deployment --without test --without development
current directory:
/usr/home/discourse/discourse/vendor/bundle/ruby/2.3.0/gems/unf_ext-0.0.7.1/ext/unf_ext
make "DESTDIR="
compiling unf.cc
g++: error: unrecognized command line option '-Wshorten-64-to-32'
g++: error: unrecognized command line option '-Wdivision-by-zero'
g++: error: unrecognized command line option '-Wextra-tokens'
*** Error code 1

config.log shows the configure script recognizes clang and g++ at the same time. I'm not sure why the configure script mix up compilers. Removing gcc fixed that though.

@lacostenycoder
Copy link

@glaszig @NuLL3rr0r I'm on Mac OSX with Homebrew. My solution was centered around my $PATH variable to use my system defaults loading /usr/bin/* first
If I loaded /usr/local/bin first, that's when all would fail.

~ % g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
~ % gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
~ % clang -v
Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
~ % which gcc
/usr/bin/gcc
~ % which g++
/usr/bin/g++
~ % which clang
/usr/bin/clang
~ % which cc
/usr/bin/cc

Not sure if that helps but hopefully it sheds some kind of light.

@NuLL3rr0r
Copy link

@lacostenycoder thank you so much for the info. I'll try that next time to see what happens.

Thank you.

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

Successfully merging a pull request may close this issue.