4

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?

3
  • node-gyp builds addons for the current system/installation of node. 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. Commented Jul 19, 2013 at 6:36
  • But I can ship all my cpp files as part of the package and compile them during the install time, right? Commented Jul 19, 2013 at 13:35
  • Yeah. NPM will default { "scripts": { "install": ... } } in the package.json to "node-gype rebuild" in projects with files matching *.gyp. Commented Jul 19, 2013 at 16:33

1 Answer 1

12

I finally figured out a way to do this.

node-gyp clean configure build --verbose --arch=ia32
3
  • 1
    Is it possible to add the option as a gyp file directive? Because that would save the user a bit of time.
    – Charlie
    Commented Jun 30, 2015 at 13:21
  • 1
    It also looks like it's only the configuration step that needs to be aware of the system's architecture.
    – Charlie
    Commented Jun 30, 2015 at 13:26
  • 1
    Is there an exhaustive list for the --arch values? Where did you find the value you used?
    – David Choi
    Commented Mar 1, 2023 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.