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

Compile c++ Addon using G++ 9.2 on macOS High Sierra, '-stdlib=libc++' #1931

Closed
ArthoPacini opened this issue Oct 20, 2019 · 6 comments
Closed
Labels

Comments

@ArthoPacini
Copy link

  • Node Version: v12.11.1 and 6.12.0
  • Platform: Darwin 17.7.0 Darwin Kernel Version 17.7.0: Sun Jun 2 20:31:42 PDT 2019; root:xnu-4570.71.46~1/RELEASE_X86_64 x86_64
  • Compiler: g++-9 (Homebrew GCC 9.2.0_1) 9.2.0
  • Module: custom simple own c++ module

So i'm creating a c++ module to node, I was using the default clang++ compiler and it was great, but at some point i needed to use the library, but clang++ does not ship with it. The works on G++ 9.2 though, so i switched the compiler that node-gyp uses to my g++-9 and i got this error : g++-9: error: unrecognized command line option '-stdlib=libc++'

indeed GCC does not recognize this command line option, so i tried to remove this argument but could'nt find a way, i tried using 'cflags!' : ['-stdlib=libc++'] and 'cflags_cc!' : ['-stdlib=libc++'] on binding.gyp but none of these worked.

  • How can i disable this compiler command line option '-stdlib=libc++'?

also, i've tried to use boost/filesystem, it compiles perfectly on clang++, but throws and error on runtime, that's why i'm sticking with gcc.

env CC=/usr/local/Cellar/gcc/9.2.0_1/bin/gcc-9 CXX=/usr/local/Cellar/gcc/9.2.0_1/bin/g++-9  node-gyp rebuild --verbose
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/usr/local/Cellar/node/12.11.1/bin/node',
gyp verb cli   '/usr/local/bin/node-gyp',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose'
gyp verb cli ]
gyp info using node-gyp@6.0.0
gyp info using node@12.11.1 | darwin | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - executable path is "/usr/local/opt/python/bin/python3.7"
gyp verb find Python - executing "/usr/local/opt/python/bin/python3.7" to get version
gyp verb find Python - version is "3.7.4"
gyp info find Python using Python version 3.7.4 found at "/usr/local/opt/python/bin/python3.7"
gyp verb get node dir no --target version specified, falling back to host node version: 12.11.1
gyp verb command install [ '12.11.1' ]
gyp verb install input version string "12.11.1"
gyp verb install installing version: 12.11.1
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 12.11.1
gyp verb build dir attempting to create "build" dir: /Users/arthopacini/Desktop/Code/Rename/build
gyp verb build dir "build" dir needed to be created? /Users/arthopacini/Desktop/Code/Rename/build
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: /Users/arthopacini/Desktop/Code/Rename/build/config.gypi
gyp verb config.gypi checking for gypi file: /Users/arthopacini/Desktop/Code/Rename/config.gypi
gyp verb common.gypi checking for gypi file: /Users/arthopacini/Desktop/Code/Rename/common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
gyp info spawn /usr/local/opt/python/bin/python3.7
gyp info spawn args [
gyp info spawn args   '/usr/local/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   '/Users/arthopacini/Desktop/Code/Rename/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/arthopacini/Library/Caches/node-gyp/12.11.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/arthopacini/Library/Caches/node-gyp/12.11.1',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/arthopacini/Library/Caches/node-gyp/12.11.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/arthopacini/Desktop/Code/Rename',
gyp info spawn args   '-Dnode_engine=v8',
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 args ]
gyp verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /Users/arthopacini/Library/Caches/node-gyp/12.11.1
gyp verb `which` succeeded for `make` /usr/bin/make
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
  /usr/local/Cellar/gcc/9.2.0_1/bin/g++-9 '-DNODE_GYP_MODULE_NAME=rename' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DBUILDING_NODE_EXTENSION' -I/Users/arthopacini/Library/Caches/node-gyp/12.11.1/include/node -I/Users/arthopacini/Library/Caches/node-gyp/12.11.1/src -I/Users/arthopacini/Library/Caches/node-gyp/12.11.1/deps/openssl/config -I/Users/arthopacini/Library/Caches/node-gyp/12.11.1/deps/openssl/openssl/include -I/Users/arthopacini/Library/Caches/node-gyp/12.11.1/deps/uv/include -I/Users/arthopacini/Library/Caches/node-gyp/12.11.1/deps/zlib -I/Users/arthopacini/Library/Caches/node-gyp/12.11.1/deps/v8/include -I../node_modules/nan  -Os -gdwarf-2 -mmacosx-version-min=10.10 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -std=c++17 -lboost_system -lboost_filesystem -O0 -MMD -MF ./Release/.deps/Release/obj.target/rename/cpp/rename.o.d.raw   -c -o Release/obj.target/rename/cpp/rename.o ../cpp/rename.cc
g++-9: error: unrecognized command line option '-stdlib=libc++'
make[1]: *** [Release/obj.target/rename/cpp/rename.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/usr/local/Cellar/node/12.11.1/bin/node" "/usr/local/bin/node-gyp" "rebuild" "--verbose"
gyp ERR! cwd /Users/arthopacini/Desktop/Code/Rename
gyp ERR! node -v v12.11.1
gyp ERR! node-gyp -v v6.0.0
gyp ERR! not ok
@cclauss
Copy link
Contributor

cclauss commented Oct 20, 2019

Related to #469 ?

@cclauss cclauss added the macOS label Oct 24, 2019
@ArthoPacini
Copy link
Author

actually I would like to disable the -stdlib=libc++ compiler flag

@bnoordhuis
Copy link
Member

How can i disable this compiler command line option '-stdlib=libc++'?

I'm afraid the answer right now is "you can't."

node-gyp inherits the setting from node's CLANG_CXX_LIBRARY setting in common.gypi:

https://github.com/nodejs/node/blob/009952935f253405ac095a4aaaa762fb080b7cb9/common.gypi#L482

xcode_emulation.py translates that to -stdlib=libc++ in cflags_cc but at a time when cflags_cc! no longer works.

As a workaround, you can run node-gyp rebuild -- -Dclang=0 (the stanza in common.gypi is guarded on clang==1) but that probably doesn't help you when you want to publish your module.

@ArthoPacini
Copy link
Author

that's actually sad :(
today at night I gonna try build with -Dclang=0 as you described, but damn, I just would like to update the clang compiler on macOS to support the , apple is so bizarre with compiler updates.
Thanks!

@rvagg
Copy link
Member

rvagg commented Oct 30, 2019

@ArthoPacini if you're up to it then we'd consider a patch to gyp here to add some functionality to support what you need. Tests would be nice even if they involved mocks but I know that might get awkward.

@Heziode
Copy link

Heziode commented Oct 13, 2020

Is there a way to passing -Dclang=0 to node-gyp when we npm rebuild ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants