运行node-gyp中hello world例子出错
发布于 8 年前 作者 qianhao5316357 3114 次浏览 来自 问答

根据网上教程先创建3个文件 创建文件

binding.gyp: { “targets”: [ { “target_name”: “hello”, “sources”: [ “hello.cc” ] } ]

hello.cc: #include <node.h> #include <v8.h> using namespace v8; Handle<Value> Method(const Arguments& args) { HandleScope scope; return scope.Close(String::New(“hello,world”)); } void init(Handle<Object> exports) { exports->Set(String::NewSymbol(“hello”), FunctionTemplate::New(Method)->GetFunction()); } NODE_MODULE(hello, init)

test.js: var addon = require(’./build/Release/hello’); console.log(addon.hello()); 4.运行 node-gyp configure build /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 错误代码如下 : E:\新建文件夹\hellocc>node-gyp configure build gyp info it worked if it ends with ok gyp info using node-gyp@3.4.0 gyp info using node@6.2.0 | win32 | ia32 gyp info spawn C:\Python27\python.EXE gyp info spawn args [ ‘C:\Users\Administrator\AppData\Roaming\npm\node_mod ules\.node-gyp_npminstall\node_modules\.3.4.0@node-gyp\gyp\gyp_main.py’, gyp info spawn args ‘binding.gyp’, gyp info spawn args ‘-f’, gyp info spawn args ‘msvs’, gyp info spawn args ‘-G’, gyp info spawn args ‘msvs_version=auto’, gyp info spawn args ‘-I’, gyp info spawn args ‘E:\新建文件夹\hellocc\build\config.gypi’, gyp info spawn args ‘-I’, gyp info spawn args ‘C:\Users\Administrator\AppData\Roaming\npm\node_mod ules\.node-gyp_npminstall\node_modules\.3.4.0@node-gyp\addon.gypi’, gyp info spawn args ‘-I’, gyp info spawn args ‘C:\Users\Administrator\.node-gyp\6.2.0\include\node \common.gypi’, gyp info spawn args ‘-Dlibrary=shared_library’, gyp info spawn args ‘-Dvisibility=default’, gyp info spawn args ‘-Dnode_root_dir=C:\Users\Administrator\.node-gyp\6.2. 0’, gyp info spawn args ‘-Dnode_gyp_dir=C:\Users\Administrator\AppData\Roaming \npm\node_modules\.node-gyp_npminstall\node_modules\.3.4.0@node-gyp’, gyp info spawn args ‘-Dnode_lib_file=node.lib’, gyp info spawn args ‘-Dmodule_root_dir=E:\新建文件夹\hellocc’, gyp info spawn args ‘–depth=.’, gyp info spawn args ‘–no-parallel’, gyp info spawn args ‘–generator-output’, gyp info spawn args ‘E:\新建文件夹\hellocc\build’, gyp info spawn args ‘-Goutput_dir=.’ ] gyp info spawn C:\Program Files\MSBuild\12.0\bin\msbuild.exe gyp info spawn args [ ‘build/binding.sln’, gyp info spawn args ‘/clp:Verbosity=minimal’, gyp info spawn args ‘/nologo’, gyp info spawn args ‘/p:Configuration=Release;Platform=Win32’ ] 在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。 hello.cc win_delay_load_hook.cc …\hello.cc(6): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int (…\hello.cc) [E:\新建文件夹\hellocc\build\hello.vcxproj] …\hello.cc(6): error C2143: 语法错误 : 缺少“,”(在“&”的前面) (…\hello.cc) [ E:\新建文件夹\hell occ\build\hello.vcxproj] …\hello.cc(7): error C2248: “v8::HandleScope::HandleScope”: 无法访问 protecte d 成员( 在“v8::HandleScope”类中声明) (…\hello.cc) [E:\新建文件夹\hellocc\build\hello. vcxproj] c:\users\administrator.node-gyp\6.2.0\include\node\v8.h(904) : 参见“ v8 ::HandleScope::HandleScope”的声明 c:\users\administrator.node-gyp\6.2.0\include\node\v8.h(888) : 参见“ v8 ::HandleScope”的声明 …\hello.cc(8): error C2039: “Close”: 不是“v8::HandleScope”的成员 (…\hello. cc) [E:
新建文件夹\hellocc\build\hello.vcxproj] c:\users\administrator.node-gyp\6.2.0\include\node\v8.h(888) : 参见“ v8 ::HandleScope”的声明 …\hello.cc(8): error C2039: “New”: 不是“v8::String”的成员 (…\hello.cc) [E: \新建文件夹\h ellocc\build\hello.vcxproj] c:\users\administrator.node-gyp\6.2.0\include\node\v8.h(2099) : 参见 “v 8::String”的声明 …\hello.cc(8): error C3861: “New”: 找不到标识符 (…\hello.cc) [E:\新建文件夹 \hellocc\bui ld\hello.vcxproj] …\hello.cc(12): error C2039: “NewSymbol”: 不是“v8::String”的成员 (…\hello. cc) [E:
新建文件夹\hellocc\build\hello.vcxproj] c:\users\administrator.node-gyp\6.2.0\include\node\v8.h(2099) : 参见 “v 8::String”的声明 …\hello.cc(13): error C2664: “v8::Localv8::FunctionTemplate v8::FunctionTemp

late::New(v8::Isolate *,v8::FunctionCallback,v8::Localv8::Value,v8::Local<v8: :Signature>,int)”: 无法将参数 1 从“v8::Localv8::Value (__cdecl *)(const int) ”转换为“v8 ::Isolate *” (…\hello.cc) [E:\新建文件夹\hellocc\build\hello.vcxproj] 没有使该转换得以执行的上下文 …\hello.cc(13): error C2227: “->GetFunction”的左边必须指向类/结构/联合/泛型类 型 (…\hello.cc) [E:\新建文件夹\hellocc\build\hello.vcxproj] …\hello.cc(12): error C3861: “NewSymbol”: 找不到标识符 (…\hello.cc) [E:\新 建文件夹\hell occ\build\hello.vcxproj] gyp ERR! build error gyp ERR! stack Error: C:\Program Files\MSBuild\12.0\bin\msbuild.exe failed wit h exit code: 1 gyp ERR! stack at ChildProcess.onExit (C:\Users\Administrator\AppData\Roamin g\npm\node_modules.node-gyp_npminstall\node_modules.3.4.0@node-gyp\lib\build.j s:276:23) gyp ERR! stack at emitTwo (events.js:106:13) gyp ERR! stack at ChildProcess.emit (events.js:191:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_proces s.js:204:12) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command “C:\Program Files\nodejs\node.exe” “C:\Users\Administrator \AppData\Roaming\npm\node_modules\.node-gyp_npminstall\node_modules\.3.4. 0@node-gyp\bin\node-gyp.js” “configure” "build" gyp ERR! cwd E:\新建文件夹\hellocc gyp ERR! node -v v6.2.0 gyp ERR! node-gyp -v v3.4.0 gyp ERR! not ok ////////////////////////////////////////////////////////////////////// 是否是编译器的问题?我用的是 vs 2013

2 回复

好像是这个hello.cc有问题

已经解决:这个例子版本太老了;去NODE 官网找到了最新的事例

回到顶部