简体   繁体   English

如何将node-waf wscript转换为node-gyp binding.gyp

[英]How to convert node-waf wscript to node-gyp binding.gyp

I am writing a C addon for nodejs, and I can compile and create my module with node-waf without any problem. 我正在为nodejs编写一个C插件,我可以使用node-waf编译和创建我的模块而没有任何问题。 But I need to use node-gyp and when I try to build the module using node-gyp build I get the following error ( node-gyp configure finishes successfully): 但我需要使用node-gyp,当我尝试使用node-gyp build模块时,我得到以下错误( node-gyp configure成功完成):

gyp info it worked if it ends with ok
gyp info using node-gyp@0.9.5
gyp info using node@0.8.23 | linux | ia32
make: Entering directory `/root/src/...'
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/mymodule/mymodule.o
../mymodule.cc:4:21: warning: MymoduleAPI.hh: No such file or directory
../mymodule.cc:11: error: expected initializer before '*' token
../mymodule.cc: In function 'v8::Handle<v8::Value> get_L2TPSettings(const v8::Arguments&)':
../mymodule.cc:23: error: 'api' was not declared in this scope
../mymodule.cc: In function 'v8::Handle<v8::Value> set_L2TPSettings(const v8::Arguments&)':
../mymodule.cc:39: error: 'api' was not declared in this scope
../mymodule.cc: In function 'void init(v8::Handle<v8::Object>)':
../mymodule.cc:79: error: 'MymoduleAPI' was not declared in this scope
../mymodule.cc:79: error: 'create' was not declared in this scope
../mymodule.cc:80: error: expected primary-expression before ')' token
../mymodule.cc:83: error: expected primary-expression before ')' token
../mymodule.cc:83: error: expected `;' before 'dlsym'
../mymodule.cc:85: error: expected primary-expression before 'void'
../mymodule.cc:85: error: expected `)' before 'void'
../mymodule.cc:88: error: 'api' was not declared in this scope
../mymodule.cc:76: warning: unused variable 'handle'
make: *** [Release/obj.target/mymodule/mymodule.o] Error 1
make: Leaving directory `/root/src/...'
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:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack     at Process._handle.onexit (child_process.js:680:10)
gyp ERR! System Linux 2.6.11-1.1369_FC4
gyp ERR! command "node" "/usr/local/bin/node-gyp" "build"
gyp ERR! cwd /root/src/...
gyp ERR! node -v v0.8.23
gyp ERR! node-gyp -v v0.9.5
gyp ERR! not ok

I guess that my problem could be caused by the difference between my wscript and binding.gyp . 我想我的问题可能是由我的wscriptbinding.gyp之间的差异引起的。 Does anybody know how to convert this wscript to binding.gyp ? 有谁知道如何将此wscript转换为binding.gyp

import Options
from os import unlink, symlink, popen
from os.path import exists

srcdir = "."
blddir = "build"
VERSION = "0.0.1"

def set_options(opt):
  opt.tool_options("compiler_cxx")

def configure(conf):
  conf.check_tool("compiler_cxx")
  conf.check_tool("node_addon")
  conf.env.append_value('LINKFLAGS', 
     [])

def build(bld):
  obj = bld.new_task_gen("cxx", "shlib", "node_addon")
  obj.target = "mymodule"
  obj.source = "mymodule.cc"
  obj.cxxflags = ["-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE",
        "-I/root/src/../api"]
  obj.lib = []

def shutdown():
  if Options.commands['clean']:
    if exists('mymodule.node'): unlink('mymodule.node')
  else:
    if exists('build/Release/mymodule.node') and not exists('mymodule.node'):
      symlink('build/Release/mymodule.node', 'mymodule.node')

and my current binding.gyp is: 和我目前的binding.gyp是:

{
  "targets": [
    {
      "target_name": "mymodule",
      "sources": [ "mymodule.cc" ],
     }
    ]
}

If you think that the problem is caused by something else (other than config file), your idea is welcome. 如果您认为问题是由其他原因(配置文件除外)引起的,那么您的想法是值得欢迎的。

The answer is: 答案是:

{
  "targets": [
    {
      "target_name": "mymodule",
      "include_dirs": "/root/src/../api",
      "sources": [ "mymodule.cc" ],
     }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM