关于node-gyp的问题,希望的各位大神解答
发布于 11天前 作者 zhlhuang 106 次浏览 来自 问答

安装了node-gyp 工具 打算用C++编写node模块。安装之后可以执行node-gyp 命令, node-gyp configure 是OK的


➜  C++ git:(master) ✗ sudo node-gyp configure                                                                                                                                                                                      
gyp info it worked if it ends with ok                                                                                                                                                                                              
gyp info using [email protected]                                                                                                                                                                                                      
gyp info using [email protected] | linux | x64                                                                                                                                                                                           
gyp info spawn python2                                                                                                                                                                                                             
gyp info spawn args [ '/usr/lib/node_modules/node-gyp/gyp/gyp_main.py',                                                                                                                                                            
gyp info spawn args   'binding.gyp',                                                                                                                                                                                               
gyp info spawn args   '-f',                                                                                                                                                                                                        
gyp info spawn args   'make',                                                                                                                                                                                                      
gyp info spawn args   '-I',                                                                                                                                                                                                        
gyp info spawn args   '/home/coding/workspace/C++/build/config.gypi',                                                                                                                                                              
gyp info spawn args   '-I',                                                                                                                                                                                                        
gyp info spawn args   '/usr/lib/node_modules/node-gyp/addon.gypi',                                                                                                                                                                 
gyp info spawn args   '-I',                                                                                                                                                                                                        
gyp info spawn args   '/home/coding/.node-gyp/0.12.3/common.gypi',                                                                                                                                                                 
gyp info spawn args   '-Dlibrary=shared_library',                                                                                                                                                                                  
gyp info spawn args   '-Dvisibility=default',                                                                                                                                                                                      
gyp info spawn args   '-Dnode_root_dir=/home/coding/.node-gyp/0.12.3',                                                                                                                                                             
gyp info spawn args   '-Dmodule_root_dir=/home/coding/workspace/C++',                                                                                                                                                              
gyp info spawn args   '--depth=.',                                                                                                                                                                                                 
gyp info spawn args   '--no-parallel',                                                                                                                                                                                             
gyp info spawn args   '--generator-output',                                                                                                                                                                                        
gyp info spawn args   'build',                                                                                                                                                                                                     
gyp info spawn args   '-Goutput_dir=.' ]                                                                                                                                                                                           
gyp info ok   

可是到了node-gyp build 就失败了

                                   ^                                                                                                                                                                                               
../hello.cc:13:35: note: candidate is:                                                                                                                                                                                             
In file included from /home/coding/.node-gyp/0.12.3/src/node.h:61:0,                                                                                                                                                               
                 from ../hello.cc:1:                                                                                                                                                                                               
/home/coding/.node-gyp/0.12.3/deps/v8/include/v8.h:3455:34: note: static v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate*, v8::FunctionCallback, v8::Handle<v8::Value>, v8::Handle<v8::Signature>, int)      
   static Local<FunctionTemplate> New(                                                                                                                                                                                             
                                  ^                                                                                                                                                                                                
/home/coding/.node-gyp/0.12.3/deps/v8/include/v8.h:3455:34: note:   no known conversion for argument 1 from ‘v8::Handle<v8::Value>(const int&)’ to ‘v8::Isolate*’                                                                  
../hello.cc: In function ‘v8::Handle<v8::Value> Method(const int&)’:                                                                                                                                                               
../hello.cc:9:1: warning: control reaches end of non-void function [-Wreturn-type]                                                                                                                                                 
 }                                                                                                                                                                                                                                 
 ^                                                                                                                                                                                                                                 
make: *** [Release/obj.target/hello/hello.o] Error 1                                                                                                                                                                               
make: Leaving directory `/home/coding/workspace/C++/build'                                                                                                                                                                         
gyp ERR! build error                                                                                                                                                                                                               
gyp ERR! stack Error: `make` failed with exit code: 2                                                                                                                                                                              
gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/node-gyp/lib/build.js:269:23)                                                                                                                                     
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)                                                                                                                                                                         
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)                                                                                                                                               
gyp ERR! System Linux 3.13.0-49-generic                                                                                                                                                                                            
gyp ERR! command "node" "/usr/bin/node-gyp" "build"                                                                                                                                                                                
gyp ERR! cwd /home/coding/workspace/C++                                                                                                                                                                                            
gyp ERR! node -v v0.12.3                                                                                                                                                                                                           
gyp ERR! node-gyp -v v2.0.1                                                                                                                                                                                                        
gyp ERR! not ok                 
1 回复

不贴个hello.cc么?多半是代码问题。 首先声明:我没撸过C/C++addon。 基于这个声明我做出如下推测: 可能是因为你写的那主函数没有返回值。。。 原因: 我稍微看过点C++,C++的int main()一定要返回值,不推荐写成void main()什么的。。。针对v8开发的addon我推测也遵循这个原则了

回到顶部