Extensions under node v0.6.0.

113 views
Skip to first unread message

RM

unread,
Nov 8, 2011, 4:31:26 AM11/8/11
to nodejs
Hi,

Is there an easy way to build and use an extension with the windows
node version?
I used to build them with node-waf under cygwin but I cannot find a
way to do it with the windows version...

Thanks

Dh

unread,
Nov 8, 2011, 10:03:27 AM11/8/11
to nodejs
I am also trying to make the hello world example for Windows but no
success so far. I am using VS2010.

I have generated a DLL with only one export named hello_module.
I am compiling with the preprocessor definition USING_V8_SHARED

When I require it in node I see garbage printed out:

C:\node-v0.6.0\Debug>node
> var hello = require('./hello.dll')

C:\node-v0.6.0\Debug\hello.dll:1
MZ´┐¢
^
...

Any help is appreciated. If I find something I will post the solution
here.

Thanks,
Donald

HeikoR

unread,
Nov 8, 2011, 1:55:01 PM11/8/11
to nodejs
Hi

Worked for me in VS 2010

- create Win32 DLL Project
- add the hello snippet from addons link in NodeJS documentation
- include node.h, v8.h, etc ...
- add include paths
- add lib path
- add
#pragma comment(lib, 'node.lib')
(for the simple hello example node.lib should suffice)
- rename target extension from .dll to .node (can change in project
setting)
- I then add post-build step to copy hello.node to test folder
eg. could add to NodeJS\Debug
then just run node.exe
var hello - require('./hello');

- NB: make sure that youraddon.node matches in
NODE_MODULE(youraddon, initproc)
I initially made the mistake of calling my module something else -
duh :)

(Built on Win7x64)

Brandon Benvie

unread,
Nov 8, 2011, 3:24:33 PM11/8/11
to nod...@googlegroups.com
Preprocessor definition: BUILDING_NODE_EXTENSION.

Bert Belder

unread,
Nov 8, 2011, 4:44:24 PM11/8/11
to nodejs
Sorry - I haven't been able to document the process and the building
process is not in its optimal shape either. Some handles:

- Compile node itself; this will generate `node.lib` that you'll have
to link to your extension. This lib file provides stubs for node
methods as well as V8 and libuv.

- Set up a DLL project

- Make sure to include <node.h>. That should automatically include the
required headers for libuv and v8. You need to set up your include
path yourself; this could be some work, don't give up :-)

- Before including node.h, `#define BUILDING_NODE_EXTENSION 1`.

- Don't rename node.exe; if the executable is renamed your extension
won't load properly.

- Rename the .dll file you generate to .node.


Denys Khanzhiyev

unread,
Nov 8, 2011, 5:03:04 PM11/8/11
to nod...@googlegroups.com
I get series of

error LNK2019: unresolved external symbol "public: static bool __cdecl node::Buffer::HasInstance(class v8::Handle<class v8::Value>)" (?HasInstance@Buffer@node@@SA_NV?$Handle@VValue@v8@@@v8@@@Z) in function ...(function in my code that uses node_buffer.h)
and

error LNK2019: unresolved external symbol _ev_unref в функции "protected: static int __cdecl FBblob::EIO_After_Read(struct eio_req *)" (?EIO_After_Read@FBblob@@KAHPAUeio_req@@@Z)


and

dumpbin.exe /LINKERMEMBER node.lib | grep @Buffer@node

shows nothing :-(
so I should reference Node Buffer in some other way...
same for ev_unref



2011/11/8 Bert Belder <bertb...@gmail.com>


--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

codepilot Account

unread,
Nov 8, 2011, 5:32:57 PM11/8/11
to nod...@googlegroups.com
I have had good luck with this. Thanks

Bert Belder

unread,
Nov 8, 2011, 6:22:20 PM11/8/11
to nodejs
On Nov 8, 11:03 pm, Denys Khanzhiyev <xden...@gmail.com> wrote:
> I get series of
>
> error LNK2019: unresolved external symbol "public: static bool __cdecl
> node::Buffer::HasInstance(class v8::Handle<class v8::Value>)"
> (?HasInstance@Buffer@node@@SA_NV?$Handle@VValue@v8@@@v8@@@Z) in function
> ...(function in my code that uses node_buffer.h)
> and
>
> error LNK2019: unresolved external symbol _ev_unref в функции "protected:
> static int __cdecl FBblob::EIO_After_Read(struct eio_req *)"
> (?EIO_After_Read@FBblob@@KAHPAUeio_req@@@Z)
>
> and
>
> dumpbin.exe /LINKERMEMBER node.lib | grep @Buffer@node
>
> shows nothing :-(
> so I should reference Node Buffer in some other way...

It's a bug. We have to mark node::Buffer for export.

> same for ev_unref

Use uv_unref().

Nathan Rajlich

unread,
Nov 8, 2011, 6:34:53 PM11/8/11
to nod...@googlegroups.com
While we're at it, Bert, what's the replacement for eio_custom and firing off custom background thread stuff?

Denys Khanzhiyev

unread,
Nov 8, 2011, 6:50:59 PM11/8/11
to nod...@googlegroups.com
Yes what for eio_custom?
It shows link errors for eio_custom too.

2011/11/9 Nathan Rajlich <nat...@tootallnate.net>

mscdex

unread,
Nov 8, 2011, 7:01:17 PM11/8/11
to nodejs
I know most(?) people are probably using VS to compile node and/or
extensions on Windows, but what about mingw? If I can get by with
using mingw for compiling extensions on Windows instead of having to
install and use VS (Express), that'd be great.

Ben Noordhuis

unread,
Nov 9, 2011, 4:01:39 AM11/9/11
to nod...@googlegroups.com
On Wed, Nov 9, 2011 at 00:34, Nathan Rajlich <nat...@tootallnate.net> wrote:
> While we're at it, Bert, what's the replacement for eio_custom and firing
> off custom background thread stuff?

uv_queue_work(). Look at src/node_crypto.cc for examples.

RM

unread,
Nov 9, 2011, 6:33:14 AM11/9/11
to nodejs
Hi there,

Thank you for your help Bert.
I applied your "recipe" to build my extension but I get an error "Out
of memory" (from process.dlopen) when I try to load it.
Any ideas?

Bert Belder

unread,
Nov 9, 2011, 6:45:35 AM11/9/11
to nodejs
Extensions need to be built with the same compiler as node.exe itself.
You'd have to build node with mingw as well.

Bert Belder

unread,
Nov 9, 2011, 6:47:24 AM11/9/11
to nodejs
On Nov 9, 12:33 pm, RM <dama...@gmail.com> wrote:
> Hi there,
>
> Thank you for your help Bert.
> I applied your "recipe" to build my extension but I get an error "Out
> of memory" (from process.dlopen) when I try to load it.
> Any ideas?

With this little information, there's not much I can do for you.

RM

unread,
Nov 9, 2011, 12:18:15 PM11/9/11
to nodejs
My bad! I had given a wrong name to my module so node could find the
init function.
Everything works fine.
Thanks again
Reply all
Reply to author
Forward
0 new messages