Node.js调用cpp

Node.js 调用 cpp

node-gyp 低版本只支持 python2.7, 可以npm run build --python=python2.7,或者

npm config set python `which python2.7`

发现还是报错,

  CC(target) Release/obj.target/nothing/node_modules/node-addon-api/src/nothing.o
  LIBTOOL-STATIC Release/nothing.a
Traceback (most recent call last):
  File "./gyp-mac-tool", line 611, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./gyp-mac-tool", line 28, in main
    exit_code = executor.Dispatch(args)
  File "./gyp-mac-tool", line 43, in Dispatch
    return getattr(self, method)(*args[1:])
  File "./gyp-mac-tool", line 246, in ExecFilterLibtool
    if not libtool_re.match(line) and not libtool_re5.match(line):
TypeError: cannot use a string pattern on a bytes-like object
make: *** [Release/nothing.a] Error 1

找到mac-tool.py(node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py),删除响应行,用./node_modules/.bin/node-gyp rebuild --python=python2.7即可。

升级之后支持 python3.7 可以了, 但是用npm run build还是 node-gyp 3.8, 要用./node_modules/.bin/node-gyp rebuild才可以??

默认都是 3.8???

node-gyp -v v3.8.0

node 自带的。

gyp ERR! command "/Users/magicly/.nvm/versions/node/v10.11.0/bin/node" "/Users/magicly/.nvm/versions/node/v10.11.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"


gyp ERR! command "/Users/magicly/.nvm/versions/node/v12.3.1/bin/node" "/Users/magicly/.nvm/versions/node/v12.3.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"

高版本支持Python v2.7, v3.5, v3.6, or v3.7了。