Windows下尝试编写node模块.

1,首先参考http://www.cnblogs.com/yupeng/p/3469444.html写了一个模块

2,按照指引运行

F:\Program Files\nodejs\mymodule>node-gyp configure build

奶奶的,一开始就少了一个node-gyp,上网一艘,原来这也是一个模块


'node-gyp' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

F:\Program Files\nodejs\mymodule>npm install -g node-gyp

安装模块,成功!
C:\Users\cutepig\AppData\Roaming\npm\node-gyp -> C:\Users\cutepig\AppData\Roamin
g\npm\node_modules\node-gyp\bin\node-gyp.js
node-gyp@3.3.1 C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp
├── graceful-fs@4.1.3
├── osenv@0.1.3 (os-tmpdir@1.0.1, os-homedir@1.0.1)
├── semver@5.1.0
├── nopt@3.0.6 (abbrev@1.0.7)
├── fstream@1.0.8 (inherits@2.0.1)
├── which@1.2.4 (isexe@1.1.2, is-absolute@0.1.7)
├── minimatch@1.0.0 (sigmund@1.0.1, lru-cache@2.7.3)
├── mkdirp@0.5.1 (minimist@0.0.8)
├── glob@4.5.3 (inherits@2.0.1, inflight@1.0.4, once@1.3.3, minimatch@2.0.10)

├── rimraf@2.5.2 (glob@7.0.3)
├── tar@2.2.1 (inherits@2.0.1, block-stream@0.0.8)
├── npmlog@2.0.2 (ansi@0.3.1, gauge@1.2.7, are-we-there-yet@1.0.6)
├── path-array@1.0.1 (array-index@1.0.0)
└── request@2.69.0 (is-typedarray@1.0.0, aws-sign2@0.6.0, forever-agent@0.6.1
, caseless@0.11.0, stringstream@0.0.5, --agent@0.4.2, oauth-sign@0.8.1, iss
tream@0.1.2, json-stringify-safe@5.0.1, extend@3.0.0, node-uuid@1.4.7, qs@6.0.2,
combined-stream@1.0.5, tough-cookie@2.2.1, mime-types@2.1.10, aws4@1.3.2, bl@1.
0.3, form-data@1.0.0-rc3, hawk@3.1.3, har-validator@2.0.6, http-signature@1.1.1)


F:\Program Files\nodejs\mymodule>node-gyp

Usage: node-gyp <command> [options]

where <command> is one of:
- build - Invokes `msbuild` and builds the module
- clean - Removes any generated build files and the "out" dir
- configure - Generates MSVC project files for the current module
- rebuild - Runs "clean", "configure" and "build" all at once
- install - Install node development files for the specified node version.
- list - Prints a listing of the currently installed node development files
- remove - Removes the node development files for the specified version

node-gyp@3.3.1 C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp
node@0.12.0

F:\Program Files\nodejs\mymodule>node-gyp configure build

再次执行,又莫名其妙失败。说是缺少python定义


gyp info it worked if it ends with ok
gyp info using node-gyp@3.3.1
gyp info using node@0.12.0 | win32 | x64
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack at failNoPython (C:\Users\cutepig\AppData\Roaming\npm\node_mo
dules\node-gyp\lib\configure.js:401:14)
gyp ERR! stack at C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp
\lib\configure.js:356:11
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:99:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Users\\cutepig\\AppData\\Roaming\\npm\\node_modules
\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd F:\Program Files\nodejs\mymodule
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

F:\Program Files\nodejs\m

F:\Program Files\nodejs\mymodule>set PYTHON=F:\sw\Python27\python.exe

F:\Program Files\nodejs\mymodule>node-gyp configure build

设置好后,运行 ,这个错误没了 

但是又多了个莫名其妙的错误 !


gyp info it worked if it ends with ok
gyp info using node-gyp@3.3.1
gyp info using node@0.12.0 | win32 | x64
gyp http GET https://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz
gyp http 200 https://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz
gyp http GET https://nodejs.org/dist/v0.12.0/SHASUMS256.txt
gyp http GET https://nodejs.org/dist/v0.12.0/x64/node.lib
gyp http GET https://nodejs.org/dist/v0.12.0/node.lib
gyp http 200 https://nodejs.org/dist/v0.12.0/SHASUMS256.txt
gyp http 200 https://nodejs.org/dist/v0.12.0/x64/node.lib
gyp http 200 https://nodejs.org/dist/v0.12.0/node.lib
gyp info spawn F:\sw\Python27\python.exe
gyp info spawn args [ 'C:\\Users\\cutepig\\AppData\\Roaming\\npm\\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 'F:\\Program Files\\nodejs\\mymodule\\build\\config.gypi',

gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\cutepig\\AppData\\Roaming\\npm\\node_modules\\
node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\cutepig\\.node-gyp\\0.12.0\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\cutepig\\.node-gyp\\0.12.0',
gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\cutepig\\AppData\\Roaming\\npm\
\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=node.lib',
gyp info spawn args '-Dmodule_root_dir=F:\\Program Files\\nodejs\\mymodule',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'F:\\Program Files\\nodejs\\mymodule\\build',
gyp info spawn args '-Goutput_dir=.' ]
Traceback (most recent call last):
File "C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp\gyp\gyp_main.
py", line 16, in <module>
sys.exit(gyp.script_main())
File "C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp
\__init__.py", line 545, in script_main
return main(sys.argv[1:])
File "C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp
\__init__.py", line 538, in main
return gyp_main(args)
File "C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp
\__init__.py", line 514, in gyp_main
options.duplicate_basename_check)
File "C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp
\__init__.py", line 91, in Load
generator = __import__(generator_name, globals(), locals(), generator_name)
File "C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp
\generator\msvs.py", line 20, in <module>
import gyp.MSVSUserFile as MSVSUserFile
File "C:\Users\cutepig\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp
\MSVSUserFile.py", line 9, in <module>
import socket # for gethostname
File "F:\sw\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: 找不到指定的程序。
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Users\cutepig\AppData\Roaming\np
m\node_modules\node-gyp\lib\configure.js:305:16)
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 "node" "C:\\Users\\cutepig\\AppData\\Roaming\\npm\\node_modules
\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd F:\Program Files\nodejs\mymodule
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

F:\Program Files\nodejs\mymodule>

 

后来俺换了一个python27,终于没有了socket的错误

但是编译又出了一堆v8的错误!

 

F:\Program Files\nodejs\mymodule>node-gyp configure build
gyp info it worked if it ends with ok
gyp info using node-gyp@3.3.1
gyp info using node@0.12.0 | win32 | x64
gyp info spawn F:\Python27\python.exe
gyp info spawn args [ 'C:\\Users\\cutepig\\AppData\\Roaming\\npm\\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 'F:\\Program Files\\nodejs\\mymodule\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\cutepig\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\cutepig\\.node-gyp\\0.12.0\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\cutepig\\.node-gyp\\0.12.0',
gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\cutepig\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=node.lib',
gyp info spawn args '-Dmodule_root_dir=F:\\Program Files\\nodejs\\mymodule',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'F:\\Program Files\\nodejs\\mymodule\\build',
gyp info spawn args '-Goutput_dir=.' ]
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”开关。
1.cpp
..\1.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [F:\Program Files\nodejs\mymodule\build\hello.
vcxproj]
..\1.cpp(6): error C2143: syntax error : missing ',' before '&' [F:\Program Files\nodejs\mymodule\build\hello.vcxproj]
..\1.cpp(7): error C2248: 'v8::HandleScope::HandleScope' : cannot access protected member declared in class 'v8::HandleScope' [F:\Program Files\nodej
s\mymodule\build\hello.vcxproj]
C:\Users\cutepig\.node-gyp\0.12.0\deps\v8\include\v8.h(816) : see declaration of 'v8::HandleScope::HandleScope'
C:\Users\cutepig\.node-gyp\0.12.0\deps\v8\include\v8.h(800) : see declaration of 'v8::HandleScope'
..\1.cpp(8): error C2039: 'Close' : is not a member of 'v8::HandleScope' [F:\Program Files\nodejs\mymodule\build\hello.vcxproj]
C:\Users\cutepig\.node-gyp\0.12.0\deps\v8\include\v8.h(800) : see declaration of 'v8::HandleScope'
..\1.cpp(8): error C2039: 'New' : is not a member of 'v8::String' [F:\Program Files\nodejs\mymodule\build\hello.vcxproj]
C:\Users\cutepig\.node-gyp\0.12.0\deps\v8\include\v8.h(1599) : see declaration of 'v8::String'
..\1.cpp(8): error C3861: 'New': identifier not found [F:\Program Files\nodejs\mymodule\build\hello.vcxproj]
..\1.cpp(12): error C2039: 'NewSymbol' : is not a member of 'v8::String' [F:\Program Files\nodejs\mymodule\build\hello.vcxproj]
C:\Users\cutepig\.node-gyp\0.12.0\deps\v8\include\v8.h(1599) : see declaration of 'v8::String'
..\1.cpp(13): error C2664: 'v8::Local<v8::FunctionTemplate> v8::FunctionTemplate::New(v8::Isolate *,v8::FunctionCallback,v8::Handle<v8::Value>,v8::Ha
ndle<v8::Signature>,int)' : cannot convert argument 1 from 'v8::Handle<v8::Value> (__cdecl *)(const int)' to 'v8::Isolate *' [F:\Program Files\nodejs
\mymodule\build\hello.vcxproj]
There is no context in which this conversion is possible
..\1.cpp(13): error C2227: left of '->GetFunction' must point to class/struct/union/generic type [F:\Program Files\nodejs\mymodule\build\hello.vcxpro
j]
..\1.cpp(12): error C3861: 'NewSymbol': identifier not found [F:\Program Files\nodejs\mymodule\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 (C:\Users\cutepig\AppData\Roaming\npm\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 "node" "C:\\Users\\cutepig\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "build"
gyp ERR! cwd F:\Program Files\nodejs\mymodule
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok

Powered by Jekyll and Theme by solid

本站总访问量