I am trying to create a Node C Addon. Mine is a 64bit machine but I need to compile the Node C Addon as a 32 bit binary. By default, node-gyp picks up all the 64 bit libraries for compilation and linking process.
{
"targets": [
{
"cflags": [ "-m32" ],
"ldflags": [ "-m elf_i386" ],
"cflags_cc": [ "-fPIC -m32" ],
"target_name": "hello",
"sources": [ "Hello.cpp" ],
}
}
This is my bindings.gyp file. I am passing -m32
in cflags and setting ldflags
as -m elf_i386
. It compiles fine but I still see -m64
as well in the verbose output of compilation process.
g++ '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' ...
-fPIC -Wall -Wextra -Wno-unused-parameter -pthread -m64 -m32 -O2 -fno-strict-aliasing
-fno-tree-vrp -fno-tree-sink -fno-rtti -fno-exceptions -fPIC -MMD -MF
./Release/.deps/Release/obj.target/hello/Hello.o.d.raw -c -o
Release/obj.target/hello/Hello.o ../Hello.cpp
And It still tries to find 64 bit libraries during the linking process and fails.
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-****/4.1.2/libstdc++.so when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
That incompatible file is actually a soft link to /lib64/libstdc++.so.6.0.8
I compile with node-gyp clean configure build --verbose
How can I override this behaviour and make node-gyp compile for 32 bit architecture?
node-gyp
builds addons for the current system/installation ofnode
. Why do you need to build 32-bit when using 64-bit? If you're hoping to distribute precompiled binaries, NPM doesn't currently offer support.{ "scripts": { "install": ... } }
in thepackage.json
to"node-gype rebuild"
in projects with files matching*.gyp
.