Mindon.IDEA

Air off, Mind on ~ / Javascript+Golang, Sci, Health… /

Build Node-Expat Under Windows

Preparea Developemtn Environment

To build node-expat module under windows, you need the nodejs addon development env ready.

  • Get and install VC++ 2010 Express from microsoft: 【Download VC++ 2010 Express

  • Download and unzip the NodeJS source code from Joyent’s github project: 【Download NodeJS source code

  • Get and install Python 2.7

  • Run vcbuild.bat Release under such as joyen-node/ (where you unzip the source of nodejs) to build NodeJS.

Tools for building a NodeJS Module

  • Env variable set NODE_ROOT=where-your-joyent-node-located

  • Check the tools/ folder in the joyent-node/: file gyp_addon, and addon.gypi are needed.

if they are not exists, try get it from the latest tag from github of joyent-node ( Left of Files tab, find branch –> Tags ).

( You could use tools/gyp_node directly )

Node-Expat Dependencis:

Building Node-Expat:

  • Prepare build.gyp ( need to change D:/Expat to your expat root )

    {
      'variables' : {
        'target_arch': 'ia32'
      },
      'targets': [
        {
          'target_name': 'node-expat',
          'sources': [ 'node-expat.cc' ],
          'include_dirs': [
        'd:/Expat/Source/lib/'
          ],
          'libraries': [
        '-ld:/Expat/Bin/libexpat.lib'
          ]
        }
      ],
    }
    
  • Run following commands

to setup build version and msbuild tool env.

@set Configuration=Release
"D:\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"

then

python d:\joyent-node\tools\gyp_addon build.gyp

msbuild build\build.sln

Now you should build the Node-Expat. But you may meet other problems:

Testing

if run node and require(“./build/Release/node-expat”) fail, it may be caused by following reasons:

a) check the node-expat.cc, and make sure there’s a NODE_MODULE_EXPORT or NODE_EXTERN before the void init

something like this: extern “C” NODE_EXTERN void init(Handle<Object> target)

b) if “unable to load shared library” error, try copy libexpat.dll to the folder of node.exe located.

  • node test.js

if when you run node test.js of expat, it may fail. Then you need following code to fix it.

char *toCString(v8::Local<v8::Value> value, const char *fallback = "") {
    if (value->IsString()) {
    v8::String::Utf8Value string(value);
    char *str = (char *) malloc(string.length() + 1);
    strcpy(str, *string);
    return str;
    }
    char *str = (char *) malloc(strlen(fallback) + 1);
    strcpy(str, fallback);
    return str;
}

add these code below using namespace node;.

then change the line around 155 before or 165 after code above added

return XML_ParseBuffer(parser, len, isFinal) != XML_STATUS_ERROR;

into

return XML_Parse(parser, toCString(&str, ""), len, isFinal) != XML_STATUS_ERROR;

This patch could help to remove the error “not well-formed (invalid token)”.

Now, your node-epxat under windows is ready for node-soap, you would need this for something like WSDL!

Comments