0

I'm out of my depth here as I don't know jack about C and such compilers, except that as per tut's I've read - I've homebrew installed gcc-4.9, linked it, and in my .bash_profile have cc=gcc-4.9 - hoping this would allow me to install Ruby 2.1.1, as previous attempts have failed, complaining about the following:

note: unrestricted unions only available with -std=c++11 or -std=gnu++11

I've visited the gcc site and seen that 4.9 includes c++11 support, so I'm confused as to why it's failing to make Ruby as per above error, and full error output below:

 make
CC = /usr/local/bin/g++-4.9
LD = ld
LDSHARED = /usr/local/bin/g++-4.9 -dynamic -bundle
CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings   -pipe 
XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE
CPPFLAGS = -I/usr/local/Cellar/openssl/1.0.1g/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -I. -I.ext/include/x86_64-darwin13.0 -I./include -I.
DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/Cellar/openssl/1.0.1g/lib  -fstack-protector -Wl,-u,_objc_msgSend -pie -framework CoreFoundation  
SOLIBS = -lgmp 
Using built-in specs.
COLLECT_GCC=/usr/local/bin/g++-4.9
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc49/4.9.0/libexec/gcc/x86_64-apple-darwin13.1.0/4.9.0/lto-wrapper
Target: x86_64-apple-darwin13.1.0
Configured with: ../configure --build=x86_64-apple-darwin13.1.0 --prefix=/usr/local/Cellar/gcc49/4.9.0 --enable-languages=c,c++,objc,obj-c++ --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp4 --with-mpfr=/usr/local/opt/mpfr2 --with-mpc=/usr/local/opt/libmpc08 --with-cloog=/usr/local/opt/cloog018 --with-isl=/usr/local/opt/isl011 --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.9.0 (GCC) 
compiling miniprelude.c
In file included from vm_core.h:24:0,
             from miniprelude.c:8:
method.h:84:19: error: member 'rb_method_attr_t rb_method_definition_struct::<anonymous union>::attr' with copy assignment operator not allowed in union
rb_method_attr_t attr;
               ^
method.h:84:19: note: unrestricted unions only available with -std=c++11 or -std=gnu++11
In file included from miniprelude.c:8:0:
vm_core.h:674:59: error: use of enum 'iseq_type' without previous declaration
VALUE rb_iseq_new(NODE*, VALUE, VALUE, VALUE, VALUE, enum iseq_type);
                                                       ^
vm_core.h:677:76: error: use of enum 'iseq_type' without previous declaration
VALUE rb_iseq_new_with_bopt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type,     VALUE);
                                                                        ^
vm_core.h:678:75: error: use of enum 'iseq_type' without previous declaration
VALUE rb_iseq_new_with_opt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, const rb_compile_option_t*);
                                                                       ^
make: *** [miniprelude.o] Error 1

As I wrote, I'm really out of my depth here, so would appreciate any help resolving this so I can install Ruby 2.1.1.

My ./configure command used is:

./configure --prefix="$HOME/.rbenv/versions/2.1.1" --with-opt-dir=/usr/local/Cellar/openssl/1.0.1g

I installed Rbenv via homebrew, so it's bin isn't in ~./rbenv but in my PATH and sym linked by homebrew from:

/usr/local/bin/rbenv -> ../Cellar/rbenv/0.4.0/bin/rbenv

I can't see any complaints about that, which makes me think I'm possibly using the wrong C-compiler, but I don't see others with the same errors, and they are happy with homebrew's gcc-4.9 or apple-gcc42, but to be honest - I have no idea how to determine which to use.

Any help appreciated as I've wasted far too long on this instead of actually developing a web app.

Thanks

manlio
  • 18,345
  • 14
  • 76
  • 126
user3591456
  • 61
  • 1
  • 3

1 Answers1

0

The error message

 note: unrestricted unions only available with -std=c++11 or -std=gnu++11

says that some feature is available, only when gcc (or g++) is started with options -std=c++11 or -std=gnu++11

So, gcc 4.9 includes c++11 support, but not enables it by default. Add command line option -std=c++11 to enable the support. Such options are usually included into CFLAGS variable. Or you can even try to add this into your CC.

I think there can be error in Ruby's configure script. This script should check for all needed features and cook right set of flags to CFLAGS, but in your case it failed to add -std=c++11 into flags.

osgx
  • 90,338
  • 53
  • 357
  • 513
  • I suspect that the build should be using gcc rather than g++. As far as I know, Ruby is written in C. – kec May 05 '14 at 00:46
  • @osgx: Thanks, I should have mentioned I had already tried installing gcc49 with: brew install gcc49 --enable-languages=c,c++,c++11 but this didn't help. So, I did this wrong? Should I reinstall it like so? brew install gcc49 --enable-languages=std=c++11 ? Sorry, I'm out of my depth here. – user3591456 May 05 '14 at 00:51
  • @kec Thanks, but all the Ruby installation tut's I've seen refer to installing gcc, not g++, but to be honest I don't even know the difference between the two of them. I'll google 'install ruby g++' now, but I think osgx is likely more on the right track. – user3591456 May 05 '14 at 00:54
  • @user3591456: Exactly, so it seems you should be using `gcc`, not `g++`, which is what you are doing. It appears that you are trying to compile Ruby with `g++`, which is the C++ compiler that comes with the GCC compiler suite. But as far as I know, Ruby is written in C, which means that you should be using `gcc`, which is the C compiler that comes with the GCC suite. – kec May 05 '14 at 00:59
  • @kec Thanks, I first tried making Ruby with gcc4.9 without any config options other than pointing to the homebrew openssl dir. So I'm confused - how can I ./configure gcc to just use C? – user3591456 May 05 '14 at 01:40
  • @user3591456: Well, I've never compiled Ruby, but if you point me to which one of these instructions you followed, then I might be able to help: https://www.ruby-lang.org/en/installation/. – kec May 05 '14 at 01:51
  • @user3591456: I took a quick look at some of those instructions. Somwhere, somehow, it seems that you set/configured something to make it use g++. I noticed that you show this line: `CC = /usr/local/bin/g++-4.9`. Normally, `CC` should be set to point to the C compiler, not the C++ compiler. – kec May 05 '14 at 01:56
  • @kec Thanks - it's installed. I uninstalled homebrew's gcc49 and commented out the additions tut's said to include in my .bash_profile: export CC=/usr/local/bin/gcc-4.9 export CC=/usr/local/bin/cpp-4.9 export CC=/usr/local/bin/g++-4.9, and instead relied on xcode's linked compiler. I'd previously tried a tut that said to only put CC=/usr/local/bin/gcc-4.9 in bash_profile, and that didn't work, and nor did using homebrew's applegcc42. My guess was that because gcc can compile C to C++ etc, as its site says, the build script would choose the right language. But I'm a noob at C and Ruby.Thanks!:) – user3591456 May 05 '14 at 02:34