node c/c++扩展模块build失败.
"深入浅出nodejs 朴灵" 例子 c/c++扩展模块
http://diveintonode.org/
在作者的帮助下,build成功. 下面贴出的hello.cc和binding.gyp都是已经过时的代码了(暂时保留).
应该以官方最新例子(https://nodejs.org/docs/latest/api/addons.html)为准.
hello.cc
- #include <node.h>
- #include <v8.h>
- using namespace v8;
- Handle<Value> SayHello(const Arguments& args){
- HandleScope scope;
- return scope.Close(String::New("Hello world!"));
- }
- void Init_Hello(Handle<Object> target){
- target->Set(String::NewSymbol("sayHello"), FunctionTemplate::New(SayHello)->GetFunction());
- }
- NODE_MODULE(hello, Init_Hello)
binding.gyp
- {
- 'targets':[
- {
- 'target_name':'hello',
- 'sources':[
- './hello.cc'
- ],
- 'conditions':[
- ['OS == "win"',
- {
- 'libraries':['-lnode.lib']
- }
- ]
- ]
- }
- ]
- }
configure没有问题:
- C:\wxg\test\nodejs\dll_demo
- λ node-gyp configure
- gyp info it worked if it ends with ok
- gyp info using node-gyp@3.2.1
- gyp info using node@0.12.1 | win32 | x64
- gyp info spawn C:\Python27\python.EXE
- gyp info spawn args [ 'E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\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 'C:\\wxg\\test\\nodejs\\dll_demo\\build\\config.gypi',
- gyp info spawn args '-I',
- gyp info spawn args 'E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\node-gyp\\addon.gypi',
- gyp info spawn args '-I',
- gyp info spawn args 'C:\\Users\\WXG\\.node-gyp\\0.12.1\\common.gypi',
- gyp info spawn args '-Dlibrary=shared_library',
- gyp info spawn args '-Dvisibility=default',
- gyp info spawn args '-Dnode_root_dir=C:\\Users\\WXG\\.node-gyp\\0.12.1',
- gyp info spawn args '-Dnode_gyp_dir=E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\node-gyp',
- gyp info spawn args '-Dnode_lib_file=node.lib',
- gyp info spawn args '-Dmodule_root_dir=C:\\wxg\\test\\nodejs\\dll_demo',
- gyp info spawn args '--depth=.',
- gyp info spawn args '--no-parallel',
- gyp info spawn args '--generator-output',
- gyp info spawn args 'C:\\wxg\\test\\nodejs\\dll_demo\\build',
- gyp info spawn args '-Goutput_dir=.' ]
- gyp info ok
build失败.
- C:\wxg\test\nodejs\dll_demo
- λ node-gyp build
- gyp info it worked if it ends with ok
- gyp info using node-gyp@3.2.1
- gyp info using node@0.12.1 | win32 | x64
- gyp info spawn c:\Windows\Microsoft.NET\Framework\v4.0.30319\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=x64' ]
- VCBUILD : error : project file 'C:\wxg\test\nodejs\dll_demo\build\hello.vcproj' was not found or not a valid p roject file. [C:\wxg\test\nodejs\dll_demo\build\binding.sln]
- gyp ERR! build error
- gyp ERR! stack Error: `c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
- gyp ERR! stack at ChildProcess.onExit (E:\wxg\Git\nvmw\v0.12.1\node_modules\node-gyp\lib\build.js:276:23)
- gyp ERR! stack at ChildProcess.emit (events.js:110:17)
- gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
- gyp ERR! System Windows_NT 6.1.7601
- gyp ERR! command "E:\\wxg\\Git\\nvmw\\v0.12.1\\\\node.exe" "E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\node-gyp\\bin\\node-gyp.js" "build"
- gyp ERR! cwd C:\wxg\test\nodejs\dll_demo
- gyp ERR! node -v v0.12.1
- gyp ERR! node-gyp -v v3.2.1
- gyp ERR! not ok
在网上搜索了下: http://www.imooc.com/qadetail/38800 , http://stackoverflow.com/questions/32964144/gyp-err-stack-error-c-program-files-x86-msbuild-12-0-bin-msbuild-exe-fail ,
最靠谱的应该还是 https://www.npmjs.com/package/node-gyp
- Windows 7/8:
- Microsoft Visual Studio C++ 2013 for Windows Desktop (Express version works well)
但是,我还没装"Microsoft Visual Studio C++ 2013", studio文件太大,下载要很久. 我在网上找的一个"Microsoft Visual C++ 2013运行库",安装了,没效果. 这个等以后下载了studio再验证下.
==============================================================================
在安装了MS studio 2013之后,仍然报错.记录如下:
- C:\wxg\test\nodejs\dll_demo
- λ node-gyp build
- gyp info it worked if it ends with ok
- gyp info using node-gyp@3.2.1
- gyp info using node@0.12.1 | win32 | x64
- gyp info spawn C:\Program Files (x86)\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=x64' ]
- 在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
- VCBUILD : error : project file 'C:\wxg\test\nodejs\dll_demo\build\hello.vcproj' was not found or not a valid p roject file. [C:\wxg\test\nodejs\dll_demo\build\binding.sln]
- gyp ERR! build error
- gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1
- gyp ERR! stack at ChildProcess.onExit (E:\wxg\Git\nvmw\v0.12.1\node_modules\node-gyp\lib\build.js:276:23)
- gyp ERR! stack at ChildProcess.emit (events.js:110:17)
- gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
- gyp ERR! System Windows_NT 6.1.7601
- gyp ERR! command "E:\\wxg\\Git\\nvmw\\v0.12.1\\\\node.exe" "E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\node-gyp\\bin\\node-gyp.js" "build"
- gyp ERR! cwd C:\wxg\test\nodejs\dll_demo
- gyp ERR! node -v v0.12.1
- gyp ERR! node-gyp -v v3.2.1
- gyp ERR! not ok
- C:\wxg\test\nodejs\dll_demo
- λ
再次执行
λ node-gyp configure
- C:\wxg\test\nodejs\dll_demo
- λ node-gyp configure
- gyp info it worked if it ends with ok
- gyp info using node-gyp@3.2.1
- gyp info using node@0.12.1 | win32 | x64
- gyp info spawn C:\Python27\python.EXE
- gyp info spawn args [ 'E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\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 'C:\\wxg\\test\\nodejs\\dll_demo\\build\\config.gypi',
- gyp info spawn args '-I',
- gyp info spawn args 'E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\node-gyp\\addon.gypi',
- gyp info spawn args '-I',
- gyp info spawn args 'C:\\Users\\WXG\\.node-gyp\\0.12.1\\common.gypi',
- gyp info spawn args '-Dlibrary=shared_library',
- gyp info spawn args '-Dvisibility=default',
- gyp info spawn args '-Dnode_root_dir=C:\\Users\\WXG\\.node-gyp\\0.12.1',
- gyp info spawn args '-Dnode_gyp_dir=E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\node-gyp',
- gyp info spawn args '-Dnode_lib_file=node.lib',
- gyp info spawn args '-Dmodule_root_dir=C:\\wxg\\test\\nodejs\\dll_demo',
- gyp info spawn args '--depth=.',
- gyp info spawn args '--no-parallel',
- gyp info spawn args '--generator-output',
- gyp info spawn args 'C:\\wxg\\test\\nodejs\\dll_demo\\build',
- gyp info spawn args '-Goutput_dir=.' ]
- gyp info okZ
再次执行
λ node-gyp build
- C:\wxg\test\nodejs\dll_demo
- λ node-gyp build
- gyp info it worked if it ends with ok
- gyp info using node-gyp@3.2.1
- gyp info using node@0.12.1 | win32 | x64
- gyp info spawn C:\Program Files (x86)\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=x64' ]
- 在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
- hello.cc
- ..\hello.cc(6): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- ..\hello.cc(6): error C2143: 语法错误 : 缺少“,”(在“&”的前面) [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- ..\hello.cc(7): error C2248: “v8::HandleScope::HandleScope”: 无法访问 protected 成员(在“v8::HandleScope”类中声明) [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- C:\Users\WXG\.node-gyp\0.12.1\deps\v8\include\v8.h(816) : 参见“v8::HandleScope::HandleScope”的声明
- C:\Users\WXG\.node-gyp\0.12.1\deps\v8\include\v8.h(800) : 参见“v8::HandleScope”的声明
- ..\hello.cc(8): error C2039: “Close”: 不是“v8::HandleScope”的成员 [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- C:\Users\WXG\.node-gyp\0.12.1\deps\v8\include\v8.h(800) : 参见“v8::HandleScope”的声明
- ..\hello.cc(8): error C2039: “New”: 不是“v8::String”的成员 [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- C:\Users\WXG\.node-gyp\0.12.1\deps\v8\include\v8.h(1599) : 参见“v8::String”的声明
- ..\hello.cc(8): error C3861: “New”: 找不到标识符 [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- ..\hello.cc(12): error C2039: “NewSymbol”: 不是“v8::String”的成员 [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- C:\Users\WXG\.node-gyp\0.12.1\deps\v8\include\v8.h(1599) : 参见“v8::String”的声明
- ..\hello.cc(12): error C2664: “v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate *,v8::FunctionCallback,v8::Handle<v8::Value>,v8::Handle<v8::Signature>,int)”: 无法将参数 1 从“v8:
- :Hand
- le<v8::Value> (__cdecl *)(const int)”转换为“v8::Isolate *” [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- 没有使该转换得以执行的上下文
- ..\hello.cc(12): error C2227: “->GetFunction”的左边必须指向类/结构/联合/泛型类型 [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- ..\hello.cc(12): error C3861: “NewSymbol”: 找不到标识符 [C:\wxg\test\nodejs\dll_demo\build\hello.vcxproj]
- gyp ERR! build error
- gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1
- gyp ERR! stack at ChildProcess.onExit (E:\wxg\Git\nvmw\v0.12.1\node_modules\node-gyp\lib\build.js:276:23)
- gyp ERR! stack at ChildProcess.emit (events.js:110:17)
- gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
- gyp ERR! System Windows_NT 6.1.7601
- gyp ERR! command "E:\\wxg\\Git\\nvmw\\v0.12.1\\\\node.exe" "E:\\wxg\\Git\\nvmw\\v0.12.1\\node_modules\\node-gyp\\bin\\node-gyp.js" "build"
- gyp ERR! cwd C:\wxg\test\nodejs\dll_demo
- gyp ERR! node -v v0.12.1
- gyp ERR! node-gyp -v v3.2.1
- gyp ERR! not ok
build 仍然失败. 看提示貌似是hello.cc文件编写错误.目前没能力搞定.先放放.
==============================================================
在作者的帮助下,build成功.
- C++的接口一直在变化,参考:https://nodejs.org/docs/latest/api/addons.html
按照官方给的例子,修改hello.cc和binding.gyp,再依次执行node-gyp configure , node-gyp build 就可以了.
- C:\wxg\test\nodejs\dll_demo
- λ node-gyp build
- gyp info it worked if it ends with ok
- gyp info using node-gyp@3.2.1
- gyp info using node@0.12.1 | win32 | x64
- gyp info spawn C:\Program Files (x86)\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=x64' ]
- 在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
- hello.cc
- win_delay_load_hook.c
- 正在创建库 C:\wxg\test\nodejs\dll_demo\build\Release\addon.lib 和对象 C:\wxg\test\nodejs\dll_demo\build\Re
- lease\a
- ddon.exp
- 正在生成代码
- 已完成代码的生成
- addon.vcxproj -> C:\wxg\test\nodejs\dll_demo\build\Release\\addon.node
- gyp info ok
- C:\wxg\test\nodejs\dll_demo
- λ node hello.js
- world
node c/c++扩展模块build失败.的更多相关文章
- TeamCity : Build 失败条件
允许用户配置 Build 失败的条件是很有用的功能,它是我们配置复杂 Build 流程的基础.TeamCity 为用户自定义 Build 失败条件提供了很好的支持.这些条件大体上可以分为两类,分别是: ...
- No compiler is provided in this environment. --Maven build失败
今天,maven build 失败了, 遇到下面的问题 经过查找,通过这个大佬的blog( https://blog.csdn.net/lslk9898/article/details/738367 ...
- IDEA配置好maven后新建maven项目一直build失败的解决方法
maven配置了aliyun中央仓库后,IDEA新建maven项目一直出现以下问题: 相信有遇到这个问题的小伙伴很蛋疼,明明maven配置没错,新建项目却一直build失败,为了这个问题我重装过几次I ...
- 【vue】解决npm run build失败问题
问题说明: 首先,npm run build失败的原因大部分都是因为webpack的子库和webpack的版本号不对应的问题
- node.js npm 安装spm失败,竟然是版本的问题
SPM v.1.1.2 With SeaJS SPM v1.1.2使用指南 1.SPM用途 SeaJS提供了模块化开发的机制,在代码开发完后,还需要做产品发布相关的一些操作. 这些可以通过SPM来 ...
- Jenkins build失败条件
在Jenkins 项目写了很多剧本.有时候,我发现脚本失败,但Jenkins运行成功. Jenkins无论是通过退出代码0比量build成功. 因此,newLISP在.您可以使用(exit)对于成功. ...
- maven web项目build失败
通过maven build发布web项目到tomcat时报如下异常: [INFO] ---------------------------------------------------------- ...
- 安装node.msi 格式的文件失败
in10 安装node.msi格式的文件,出现2503 2502 错误码, win+x 打开 在命令提示符窗口中输入: msiexec /package "安装msi格式的文件的全路径&qu ...
- maven build 失败
(1).之前项目打包都OK,不知道咋回事,突然出现如下图的问题: (2)上网查找了好多,一直没有解决,最后把本地maven库删除,重新运行了一遍,变成BUILD SUCCESS,但是警告还是The ...
随机推荐
- [一位菜鸟的COCOS-2D编程之路]精灵表单的制作以及简易动画的生成
1.第一步:使用Zwoptex 制作精灵表单 2.制作的表单的名称为 cocos2Dpng,cocos2D.plist: 3.精灵的动画效果 主要分为五部分. // on "init&quo ...
- st_MES_InsertIntoSalaryManage
USE [ChiefmesNew]GO/****** Object: StoredProcedure [dbo].[st_MES_InsertIntoSalaryManage] Script Date ...
- 关于Windows文件名和路径名的那些事
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:关于Windows文件名和路径名的那些事.
- Notes(一)
Numerous experimental measurements in spatially complex systems have revealed anomalous diffusion in ...
- 新浪旗下的SAE云服务入门
前言: 云服务已经火热很多年了,到了现在已经基本进入稳定期,稍微有实力的公司都会推出免费的云存储,像百度的还几个T,速度也不错.如果不担心数据安全问题,代替平时的U盘还是没有问题.而SAE是新浪在20 ...
- Oracle VM Virtual Box 4.3 小巧精悍的虚拟机软件
https://www.virtualbox.org/wiki/Downloads Download VirtualBox Here, you will find links to VirtualBo ...
- android学习日记03--常用控件checkbox/radiobutton
常用控件3.checkbox 复选框,确定是否勾选,点击一下勾选,点击第二下取消,当有一系列备选项时适合用checkbox控件,方便用户提交数据. 贴上例子Activity的java代码 packag ...
- 运维知识体系v0.5
http://www.90qj.com/?post=318http://ixdba.blog.51cto.com/2895551/1751377 运维知识体系v0.5-(运维社区-赵班长出品,欢迎 ...
- 文件I/O之sync、fsync和fdatasync函数
传统的UNIX实现在内核中设有缓冲区高速缓存或页面高速缓存,大多数磁盘I/O都通过缓冲进行.当将数据写入文件时,内核通常先将数据复制到其中一个缓冲区中,如果 该缓冲区尚未写满,则并不将其排入输出队列, ...
- VM11安装Mac OS X 10.10
工具/原料 1. VMware Workstation 11.12 2. unlocker 206(for OS X 插件补丁) 3. Mac OS X 10.10镜像 方法/步骤 有图有真相,哈 ...