Question

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?

Was it helpful?

Solution

I finally figured out a way to do this.

node-gyp clean configure build --verbose --arch=ia32
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top