Node-gyp笔记

Node-gyp

依赖:

  • python
  • VS
    可以直接管理员运行:
    npm install --global --production windows-build-tools

使用:

  • 编写binding.gyp,语法:
{
  'targets': [
    {
      'target_name': 'hsfProtocol',
      'sources': ['hsf_protocol.cc'],//中括号里可以逗号分开表示多个文件
      'cflags': ['-fexceptions', '-Wall', '-D_FILE_OFFSET_BITS=64','-D_LARGEFILE_SOURCE', '-O2'],    //编译选项
      'cflags_cc': ['-fexceptions', '-Wall', '-D_FILE_OFFSET_BITS=64','-D_LARGEFILE_SOURCE', '-O2'],
      'cflags!': ['-fno-exceptions'],    //关闭的编译选项
      'cflags!_cc': ['-fno-exceptions'],
      'conditions': [
        ['OS=="mac"', {    //满足此条件后开启
          'xcode_settings': {
            'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
          }
        }]
        ],
      'include_dirs': [    //引用第三方库的头文件路径
                       '../hsf_protocol/utils',
                       '../hsf_protocol/objects',
                       '../hsf_protocol/hessian',
                       '../hsf_protocol/hsf']
    }
  ]
  • node-gyp configure生成工程
  • node-gyp build生成二进制文件.node
  • 安装bindings npm install -save bindings
  • ok啦

系统位数问题:

  • 使用node-gyp build --arch ia32/x64选择不同位数
  • 调试的时候使用的electron是安装的node的位数
  • 打包的位数是打包的时候选择的位数
  • 从上到下要保持一致
发布了8 篇原创文章 · 获赞 0 · 访问量 18

猜你喜欢

转载自blog.csdn.net/u014182377/article/details/105715839