I successfully built a node add-on on windows using Visual Studio. Now I want to build the same add-on on windows but targeting Linux.
1. Is it possible to compile a node c++ add-on on windows for Linux? 2. What compiler should I install on windows? 3. Would it be possible using node-gyp?
On Oct 28, 1:15 pm, NodeNinja <aeon6f...@gmail.com> wrote:
> and was wondering if there was anyway to target multiple platforms?
Sure, you can target multiple platforms in your binding.gyp easily
using conditionals like that. However I thought you were originally
asking how to compile a Linux executable on Windows.
On Sunday, October 28, 2012 11:07:48 PM UTC+5:30, mscdex wrote:
> On Oct 28, 1:15 pm, NodeNinja <aeon6f...@gmail.com> wrote: > > and was wondering if there was anyway to target multiple platforms?
> Sure, you can target multiple platforms in your binding.gyp easily > using conditionals like that. However I thought you were originally > asking how to compile a Linux executable on Windows.
My intention in to build the addon on one system preferably having Windows OS and then use that addon on Windows and Linux. If I do something like this in binding.gyp 'conditions': [ ['OS=="linux"',
['OS=="mac"',
['OS=="win"',
] and then building the addon on windows?
1. Will three versions of the addon be generated? 2. Can I then run the addon on Windows and Linux?
On Mon, Oct 29, 2012 at 4:30 AM, NodeNinja <aeon6f...@gmail.com> wrote:
> On Sunday, October 28, 2012 11:07:48 PM UTC+5:30, mscdex wrote:
>> On Oct 28, 1:15 pm, NodeNinja <aeon6f...@gmail.com> wrote:
>> > and was wondering if there was anyway to target multiple platforms?
>> Sure, you can target multiple platforms in your binding.gyp easily
>> using conditionals like that. However I thought you were originally
>> asking how to compile a Linux executable on Windows.
> My intention in to build the addon on one system preferably having Windows
> OS and then use that addon on Windows and Linux.
> If I do something like this in binding.gyp
> 'conditions': [
> ['OS=="linux"',
> ['OS=="mac"',
> ['OS=="win"',
> ]
> and then building the addon on windows?
> 1. Will three versions of the addon be generated?
No. You need to run the node-gyp configure/build cycle once for each
platform that you target. Here is how you approximately would script
that on a UNIX system:
for OS in linux mac win; do
GYP_DEFINES="-DOS=$OS" CC=gcc-$OS CXX=g++-$OS node-gyp rebuild --arch=ia32
cp build/Release/module.node build/Release/module-$OS.node
done
CC and CXX need to point to the cross-compilers for the platform that
you're compiling for. If your module is C++ only, you can skip the CC
variable.
> 2. Can I then run the addon on Windows and Linux?
> No. You need to run the node-gyp configure/build cycle once for each > platform that you target. Here is how you approximately would script > that on a UNIX system:
> That was great news Ben,
Since I am doing this on a Windows system What cross compiler would you recommend to target Unix/Linux, gcc or MinGW?
> I recommend setting up and using a local Linux virtual machine if you > do not have access to a Linux system elsewhere.
> You might be able to get away with using a cross-compiler under > cygwin, but just mentioning that makes me cringe.
Your advice is sound mscdex... I couldn't find much info on the net for cross compiling on windows possibly install linux on a vm is a good way to start!
> You might be able to get away with using a cross-compiler under >> cygwin, but just mentioning that makes me cringe.
> Your advice is sound mscdex... > I couldn't find much info on the net for cross compiling on windows > possibly install linux on a vm is a good way to start!
Yeah...that is theoretically possible, but good luck getting libc to match, let alone your other bindings, architectures, etc.
NodeNinja:
Note that having a module that will hapilly 'npm install' on all three OSes does NOT require pre-building them. The Gyp scripting you saw does exactly that: it detects which OS it's building on and follows different instructions for each. Testing all three, on the other hand...I second mscdex' vote for using a virtual machine to test in a native environment. :)
If you're looking at an embedded system, you *might* want to cross-compile the module down to a binary on a different machine, at which point you have stepped into a different arena from simply building something that will compile and run successfully across platforms. (I'd stick it out for native compilation; YMMV.)
> Note that having a module that will hapilly 'npm install' on all three > OSes does NOT require pre-building them. The Gyp scripting you saw does > exactly that: it detects which OS it's building on and follows different > instructions for each. Testing all three, on the other hand...I second > mscdex' vote for using a virtual machine to test in a native environment. :)
> Good luck! > --Jon
Excellent Info Jonathan, the part that modules don't necessarily need to be pre built with the node-gyp system almost skipped me.