Question

I am writing a C addon for nodejs, and I can compile and create my module with node-waf without any problem. 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):

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. Does anybody know how to convert this wscript to 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:

{
  "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.

Était-ce utile?

La solution

The answer is:

{
  "targets": [
    {
      "target_name": "mymodule",
      "include_dirs": "/root/src/../api",
      "sources": [ "mymodule.cc" ],
     }
    ]
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top