在win8.1中为node-webkit编译node-sqlite3

2014/09/06

安装nodejs

本文nodejs版本0.10.31

下载node-webkit

https://github.com/rogerwang/node-webkit#downloads

If your native Node module works only with Node v0.10, then you should use node-webkit v0.8.x, which is also a maintained branch.

下载0.8.6

安装nw-gyp

npm install -g nw-gyp
nw-gyp -v

# v0.12.2
nw-gyp configure --target=0.8.6
nw-gyp build

在Windows下使用nw-gyp编译时需安装的依赖

使用nw-gyp编译本地模块 https://github.com/rogerwang/node-webkit/wiki/Build-native-modules-with-nw-gyp

For some packages you may need to use node-pre-gyp (e.g. when you get the error “Undefined variable module_name in binding.gyp while trying to load binding.gyp”), which supports building for both node.js and node-webkit by using either node-gyp or nw-gyp.

npm install -g node-pre-gyp
node-pre-gyp -v

# v0.5.22

安装编译node-sqlite3,这是从已经安装的代码再次编译

npm install sqlite3 --save
cd node_modules/sqlite3
node-pre-gyp build --runtime=node-webkit --target=0.8.6

直接从源编译安装,这个更方便

https://github.com/mapbox/node-sqlite3#building-for-node-webkit

npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=0.8.6

安装完成后将node_modules\sqlite3\lib\binding\node-webkit-v0.8.6-win32-ia32 重命名为node-webkit-v11-win32-ia32

如果同时安装了VS2012和VS2013,则会有两套msbuild.exe,直接编译时会有问题,会使用v120版

C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = ‘v100’) cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting “Upgrade Solution…”. [:\WebApp\octoo\app\node_modules\sqlite3\build\deps\action_before_build.vcxproj]

原因,解决方法参考 https://github.com/Automattic/socket.io/issues/1151

即在命令中添加参数--msvs_version=2012,例如:npm install sqlite3 --msvs_version=2012

在Fedora 21下编译时出错解决方法

AttributeError: ‘module’ object has no attribute ‘script_main’

解决方法,在命令行输入

$ python -c 'import gyp; print gyp.__file__'

返回

/usr/lib/python2.7/site-packages/gyp/__init__.pyc

移除或重命名这个目录(/usr/lib/python2.7/site-packages/gyp),让找不到即可


2015/03/25 Update

## node = 0.12.0
## nw = 0.12.0

npm install -g node-pre-gyp nw-gyp

npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=0.12.0  --msvs_version=2012 --save

## sqlite3/lib/binding/node-webkit-v0.12.0-win32-ia32/

npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=0.12.0 --save

## sqlite3/lib/binding/node-webkit-v0.12.0-linux-ia32/

## node-sqlite3 = 3.0.5