'In node-gyp binding.gyp file, how to include different library files based on the system arch (32 bit, 64bit))

I am currently trying to connect c++ with nodejs project using node-gyp. My current problem is that i have a 32 bit library file and a 64 bit library file. My computer is using 64 bit. If i used the 32 bit library files, and build it with node-gyp rebuild, it will have errors of unresolved external symbol when Im using the functions of that library, but if I used the 64 bit library, it works fine. I want to know is there a way to include a 32bit library if the computer is 32 bit and include a 64 bit library if it is 64 bit

i tried running

node-gyp clean configure build --verbose --arch=ia32

but it will return the below error when i run node index.js

testaddon.node is not a valid Win32 application.

my binding.gyp file for libraries is like below

"libraries": [
    "../cppsrc/lib/some32.lib"
]

i checked this link but it doesn't seem to have options for arch in the conditions

Thank you.



Solution 1:[1]

A possible solution (to this old question) is to name your library files according to the architecture they were build for, and then use variables in binding.gyp, which on macos and linux could be done like this:

"libraries": [
    "../cppsrc/lib/some.<!(uname -m | tr A-Z a-z).lib"
]

Depending on the shell you use, Windows probably has something equivalent.

See https://gyp.gsrc.io/docs/InputFormatReference.md#Variables-and-Conditionals for details.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 torbenl