msgpack-node icon indicating copy to clipboard operation
msgpack-node copied to clipboard

electron-rebuild and g++ issue

Open systemmind opened this issue 3 years ago • 2 comments

I using electron and when I run electron-rebuild command it shows such error:

  CXX(target) Release/obj.target/msgpackBinding/src/msgpack.o                                                                                                                                              
In file included from /home/pi/.electron-gyp/11.2.3/include/node/v8.h:30,                                                                                                                                  
                 from ../src/msgpack.cc:1:                                                                                                                                                                 
/home/pi/.electron-gyp/11.2.3/include/node/v8-internal.h: In function ‘void v8::internal::PerformCastCheck(T*)’:                                                                                           
/home/pi/.electron-gyp/11.2.3/include/node/v8-internal.h:418:38: error: ‘remove_cv_t’ is not a member of ‘std’                                                                                             
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);                                                                                                                              
                                      ^~~~~~~~~~~                                                                                                                                                          
/home/pi/.electron-gyp/11.2.3/include/node/v8-internal.h:418:38: note: suggested alternative: ‘remove_cv’                                                                                                  
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);                                                                                                                              
                                      ^~~~~~~~~~~                                                                                                                                                          
                                      remove_cv                                                                                                                                                            
/home/pi/.electron-gyp/11.2.3/include/node/v8-internal.h:418:38: error: ‘remove_cv_t’ is not a member of ‘std’                                                                                             
/home/pi/.electron-gyp/11.2.3/include/node/v8-internal.h:418:38: note: suggested alternative: ‘remove_cv’                                                                                                  
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);                                                                                                                              
                                      ^~~~~~~~~~~                                                                                                                                                          
                                      remove_cv                                                                                                                                                            
/home/pi/.electron-gyp/11.2.3/include/node/v8-internal.h:418:50: error: template argument 2 is invalid                                                                                                     
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);                                                                                                                              
                                                  ^                                                                                                                                                        
/home/pi/.electron-gyp/11.2.3/include/node/v8-internal.h:418:63: error: ‘::Perform’ has not been declared                                                                                                  
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);                                                                                                                              
                                                               ^~~~~~~                                                                                                                                     
/home/pi/.electron-gyp/11.2.3/include/node/v8-internal.h:418:63: note: suggested alternative: ‘perror’                                                                                                     
             !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);                                                                                                                              
                                                               ^~~~~~~                                                                                                                                     
                                                               perror

This issue appears because we have -std=c++11 flag in binding.gyp file:

            'cflags_cc': [
                    '-Wall',
                    '-O3',
                    '-std=c++11',
                ],

Changing this flag to -std=c++14 or removing it fixes the issue.

I am working on linux with gcc-8.

systemmind avatar Feb 11 '21 19:02 systemmind

I have a similar issue here when building with node-gyp manually from the source.

  • Operating system: macOS 11.3.1
  • Apple clang version: 12.0.5 (clang-1205.0.22.9)
# build from the root directory
$ node-gyp rebuild
# or module directory
$ npx node-gyp rebuild -C ./node_modules/msgpack
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info chdir ./node_modules/msgpack
[...]
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CC(target) Release/obj.target/libmsgpack/deps/msgpack/objectc.o
  CC(target) Release/obj.target/libmsgpack/deps/msgpack/unpack.o
  CC(target) Release/obj.target/libmsgpack/deps/msgpack/vrefbuffer.o
  CC(target) Release/obj.target/libmsgpack/deps/msgpack/zone.o
  CC(target) Release/obj.target/libmsgpack/deps/msgpack/version.o
  LIBTOOL-STATIC Release/msgpack.a
  CXX(target) Release/obj.target/msgpackBinding/src/msgpack.o
In file included from ../src/msgpack.cc:1:
In file included from /Users/user/Library/Caches/node-gyp/16.1.0/include/node/v8.h:30:
/Users/user/Library/Caches/node-gyp/16.1.0/include/node/v8-internal.h:452:38: error: no template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
            !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                ~~~~~^~~~~~~~~~~
                                     remove_cv
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:776:50: note: 'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^
1 error generated.
make: *** [Release/obj.target/msgpackBinding/src/msgpack.o] Error 1

As @systemmind said, this issue could be fixed by removing the -std=c++11 in cflags_cc attribute in binding.gyp file. In macOS, I had to remove the 'OTHER_CFLAGS': ['-std=c++11'] options as well.

Fix:

{
    "targets": [
        {
            [...]
            'cflags_cc': [
                    '-Wall',
                    '-O3'
                ],
            [...]
            'conditions': [
                ['OS=="mac"', {
                    'configurations': {
                        'Debug': {
                            'xcode_settings': {
                                'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
                                'WARNING_CFLAGS': ['-Wall', '-Wno-unused-function']
                            }
                        },
                        'Release': {
                            'xcode_settings': {
                                'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
                                'WARNING_CFLAGS': ['-Wall', '-Wno-unused-function']
                            },
                        },
                    },
                }],
               [...]

@godsflaw Can I send a PR for this issue?

henrychoi7 avatar Jun 09 '21 06:06 henrychoi7

Try this https://stackoverflow.com/a/70086482/6167132

sliterok avatar Nov 15 '22 18:11 sliterok