Node-gyp: Error "requires a C++11 compiler" while g++4.9 installed

Created on 25 May 2016  Â·  14Comments  Â·  Source: nodejs/node-gyp

I have g++ 4.9 installed but still got this error. Tried to remove ~/.node-gyp and ~/.npm and doesn't work.

g++ -v:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-3/root/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/opt/rh/devtoolset-3/root/usr --mandir=/opt/rh/devtoolset-3/root/usr/share/man --infodir=/opt/rh/devtoolset-3/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,fortran,lto --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/cloog-install --with-mpc=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.9.2 20150212 (Red Hat 4.9.2-6) (GCC) 

gcc -v:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-3/root/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/opt/rh/devtoolset-3/root/usr --mandir=/opt/rh/devtoolset-3/root/usr/share/man --infodir=/opt/rh/devtoolset-3/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,fortran,lto --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/cloog-install --with-mpc=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.9.2 20150212 (Red Hat 4.9.2-6) (GCC) 

npm install zmq:

> [email protected] install /home/xxx/xxx/xxx/node_modules/zmq
> node-gyp rebuild

make: Entering directory `/home/xxx/xxx/xxx/node_modules/zmq/build'
  CXX(target) Release/obj.target/zmq/binding.o
In file included from ../binding.cc:38:
../../nan/nan.h:43:3: error: #error This version of node/NAN/v8 requires a C++11 compiler
In file included from ../binding.cc:24:
/home/xxx/.node-gyp/6.2.0/include/node/v8.h:341: error: expected unqualified-id before ‘using’

However it builds well if I just clone zmq and manually execute node-gyp rebuild:

node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info spawn /usr/local/bin/python2
gyp info spawn args [ '/usr/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/xxx/zmq/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/xxx/.node-gyp/6.2.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/xxx/.node-gyp/6.2.0',
gyp info spawn args   '-Dnode_gyp_dir=/usr/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=node.lib',
gyp info spawn args   '-Dmodule_root_dir=/home/xxx/zmq',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory `/home/xxx/zmq/build'
  CXX(target) Release/obj.target/zmq/binding.o
  SOLINK_MODULE(target) Release/obj.target/zmq.node
  COPY Release/zmq.node
make: Leaving directory `/home/xxx/zmq/build'
gyp info ok 

Most helpful comment

It worked for me.

CC=/opt/rh/devtoolset-4/root/usr/bin/gcc CXX=/opt/rh/devtoolset-4/root/usr/bin/g++ npm install

All 14 comments

Not really a node-gyp issue. If you're using devtoolset, make sure you're running node-gyp from a devtoolset shell. Try export CC=gcc CXX=g++ before install and if that doesn't work, please file an issue with the node-zmq project.

I tried to run it in devtoolset shell but it doesn't work. However it builds well if I just clone zmq and manually execute node-gyp rebuild (see my modified issue)

It's possible npm does something that prevents devtoolset from working correctly, like running a command in a shell without passing on the environment.

Yes, you are right.

the PATH is

/opt/rh/devtoolset-3/root/usr/bin:/opt/rh/devtoolset-3/root/usr/bin:/opt/rh/devtoolset-3/root/usr/bin:......

However when invoking node-gyp rebuild in npm, the PATH is

/usr/lib/node_modules/npm/bin/node-gyp-bin:/home/xxx/node_modules/zmq/node_modules/.bin:/home/xxx/node_modules/.bin:/usr/bin:/opt/rh/devtoolset-3/root/usr/bin:/opt/rh/devtoolset-3/root/usr/bin:/opt/rh/devtoolset-3/root/usr/bin:.....

Notice that /usr/bin is appended before the real path.

After some digging I found that /usr/bin is added here:

https://github.com/npm/npm/commit/3eae40b7a681aa067dfe4fea8c9a76da5b508b48

Do you have workarounds?

'Fraid not. I'd file a npm issue.

I found that this issue has already been reported: https://github.com/npm/npm/issues/12318
Thanks for your patience :P

For those who are still wondering...

The issue in most cases is that the __node-zopfil__ package needs to be locally compiled on most systems, and it requires C++11 compilation options.

For those of you on an Ubuntu/Debian distro, this means using a _g+_+ compiler with a version 5.1 or later. If you wish to upgrade the default compiler, follow these steps:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-5.1 g++-5.1
sudo rm /bin/usr/g++
sudo ln -s /usr/bin/g++-5 /usr/bin/g++

You will still get some compiler warnings about unused functions, but the overall NPM setup and installation should proceed without error.

@jb-ertw
Thank you very much!
Just one thing, I think

sudo rm /bin/usr/g++

should be

sudo rm /usr/bin/g++

In my case, g++4.9 is installed in /opt/rh/devtoolset-3/root/usr/bin/g++ and

CC=/opt/rh/devtoolset-3/root/usr/bin/gcc CXX=/opt/rh/devtoolset-3/root/usr/bin/g++ npm install

works well. rm /usr/bin/g++ seems risky for me.

It worked for me.

CC=/opt/rh/devtoolset-4/root/usr/bin/gcc CXX=/opt/rh/devtoolset-4/root/usr/bin/g++ npm install

Thanks @megane42 it worked for me as well

CC=/opt/rh/devtoolset-2/root/usr/bin/gcc CXX=/opt/rh/devtoolset-2/root/usr/bin/g++ npm install canvas worked for me.

@arnisjuraga this worked for me too on npm install userid, thanks, dude!

centos 6.9, devtoolset-2, node 8.9.0, npm 5.5.1

Was this page helpful?
0 / 5 - 0 ratings