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

时间:2013-08-27 11:29:25

标签: node.js node-gyp

我正在为nodejs编写一个C插件,我可以使用node-waf编译和创建我的模块,没有任何问题。但我需要使用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

我猜我的问题可能是由wscriptbinding.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')

我当前的binding.gyp是:

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

如果您认为问题是由其他原因(配置文件除外)引起的,那么您的想法很受欢迎。

1 个答案:

答案 0 :(得分:2)

答案是:

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