Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native C++ Add-on on Windows Platform #3243

Closed
bleib1dj opened this issue Oct 27, 2015 · 7 comments
Closed

Native C++ Add-on on Windows Platform #3243

bleib1dj opened this issue Oct 27, 2015 · 7 comments

Comments

@bleib1dj
Copy link

System Information

Platform: Windows 7 64-bit
Electron Version: 0.34.1
npm Version: 2.14.7
node Version: 4.2.1

Issue

I'm working on utilizing a native add-on in electron. I've followed the examples provided in the docs and have been able to get them to load up in electron on OS X 10.11.1 without an issue. However, on Windows node-gyp completes its build and the add-on executes from the command line using node ./, but when I launch the same code into electron I receive the following:

Uncaught Error: The system cannot find message text for message number 0x%1 in the message file
%2. C:\...\hello.node
ATOM_SHELL_ASAR.js: 137

After reading around a bit I also tried compiling it to a 32-bit arch which also built successfully but then resulted in electron throwing:

Uncaught Error: %1 is not a valid Win32 application C:\..\hello.node
ATOM_SHELL_ASAR.js: 137

Additional Information

StackOverflow: Calling Node Native Addons C++ in Electron

@anaisbetts
Copy link
Contributor

Uncaught Error: %1 is not a valid Win32 application

This is code for "You tried to load a 32-bit DLL in a 64-bit EXE" or vice versa. electron-rebuild just handles architectures for you

@bleib1dj
Copy link
Author

Thanks @paulcbettsl. Even when built to the 64-bit architecture which is what my machine is, I'm receiving:

Uncaught Error: The system cannot find message text for message number 0x%1 in the message file
%2. C:\...\hello.node
ATOM_SHELL_ASAR.js: 137

I installed electron-rebuild, ran it, and opened electron after it completed but still received the same error.

@bleib1dj
Copy link
Author

@paulcbetts I got it to work by adding the --dist-url flag as called out in the docs. Thanks for the help and sorry to waste your time.

@ruipimentel
Copy link

Sorry to bring this topic up again, but... Where exactly did you add the --dist-url flag, and with which argument (if anyone at all)?
I'm having this exact same problem with both node-hid and serialport modules.
Thank you in advance!

@bleib1dj
Copy link
Author

http://electron.atom.io/docs/v0.36.7/tutorial/using-native-node-modules/#the-node-gyp-way

$ cd /path-to-module/
$ electron-gyp node-gyp rebuild --target=0.29.1 --arch=x64 --dist-url=https://atom.io/download/atom-shell

@ruipimentel are you trying the what is above and still seeing the issue?

@ruipimentel
Copy link

Hi, @bleib1dj , thanks for your fast answer!
Since then, I've been trying to get this to work, but no success so far, so I guess I'll have to make a little more questions... :s

Quick question #1

$ electron-gyp node-gyp rebuild --target=0.29.1 --arch=x64 --dist-url=https://atom.io/download/atom-shell

You meant this instead, right?

$ set HOME=C:\Users\MyUserName.electron-gyp
$ node-gyp rebuild --target=0.29.1 --arch=x64 --dist-url=https://atom.io/download/atom-shell

Quick question #2

There would be no problem changing --target to 0.36.7, which is the version I intend to use... right?

Quick question #3

What are these "development headers"? I'm assuming we're talking about C/C++ headers, but from what (Node, Electron, or the module itself)?

Quick question #4

While trying to run node-gyp rebuild using the above parameters, I get an error:
gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
What does it mean?


I'm sorry for bothering you again, but unfortunately I couldn't get it to work alone, even though I'm trying really hard to understand things... :/
Unfortunately I have no experience developing modules, I'm actually quite new to NodeJS, Electron and stuff, and just trying to get node-hid and serialportto work.

And, again, thank you for your help!!

@bleib1dj
Copy link
Author

Question 1: Yup
Question 2: There shouldn't be an issue with updating the target, but I'm not 100% on that one
Question 3: Again I'm not 100% on this one but I believe you are correct on the C/C++ headers and I also believe they are the headers from Electron/Atom. Drawing this from the documentation at the top of the article:

The native Node modules are supported by Electron, but since Electron is using a different V8 version
from official Node, you have to manually specify the location of Electron's headers when building 
native modules

Question 4: Without seeing your setup it's hard to know what the root cause of that error is. Might wanna try looking at the description here https://github.com/nwjs/nw.js/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.

And not a problem, just as a note though for questions about usage of electron you'll probably want to use stack overflow or the discussion forum https://discuss.atom.io/c/electron rather than the issue log. Hope it helps :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants