Skip to content

The '--target_arch' parameter does not work #669

Open

Description

@shibd

building for macOS-arm64 but attempting to link with file built for macOS-x86_64

When I execute the following command:

npx node-pre-gyp configure --target_arch="x64"

You can see that the log output is still used arm64.

node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@1.0.9
node-pre-gyp info using node@18.9.1 | darwin | arm64
gyp info it worked if it ends with ok
gyp info using node-gyp@9.1.0
gyp info using node@18.9.1 | darwin | arm64
gyp info find Python using Python version 3.10.6 found at "/opt/homebrew/opt/python@3.10/bin/python3.10"
gyp info spawn /opt/homebrew/opt/python@3.10/bin/python3.10
gyp info spawn args [
gyp info spawn args   '/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',

Then it fails when I build:

npx node-pre-gyp build --target_arch=x64

  CC(target) Release/obj.target/nothing/node_modules/node-addon-api/nothing.o
  LIBTOOL-STATIC Release/nothing.a
warning: /Library/Developer/CommandLineTools/usr/bin/libtool: archive library: Release/nothing.a the table of contents is empty (no object file members in the library define global symbols)
  SOLINK_MODULE(target) Release/Pulsar.node
ld: archive has no table of contents file '../pkg/lib/libpulsarwithdeps.a' for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/Pulsar.node] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:201:23)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Darwin 21.6.0

Activity

  1. shibd commented on Oct 21, 2022

    @shibd
    Author

    ../pkg/lib/libpulsarwithdeps.a is have, it is x86_64 static library that I compiled through it.

    This is my binding.gyp configuration:

    binding.gyp
    
    
    {
      'conditions': [
        ['OS=="win"', {
          'variables': {
            'os_arch%': '<!(echo %OS_ARCH%)',
          }
        }],
      ],
      "targets": [
        {
          "target_name": "Pulsar",
          "cflags_cc": ["-std=gnu++11"],
          "cflags!": ["-fno-exceptions"],
          "cflags_cc!": ["-fno-exceptions", "-std=gnu++14", "-std=gnu++17"],
          "include_dirs": [
            "<!@(node -p \"require('node-addon-api').include\")",
          ],
          "defines": ["NAPI_VERSION=4"],
          "sources": [
            "src/addon.cc",
            "src/Message.cc",
            "src/MessageId.cc",
            "src/Authentication.cc",
            "src/Client.cc",
            "src/SchemaInfo.cc",
            "src/Producer.cc",
            "src/ProducerConfig.cc",
            "src/Consumer.cc",
            "src/ConsumerConfig.cc",
            "src/Reader.cc",
            "src/ReaderConfig.cc",
            "src/ThreadSafeDeferred.cc"
          ],
          'conditions': [
            ['OS=="mac"', {
              'xcode_settings': {
                'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
                'GCC_ENABLE_CPP_RTTI': 'YES',
                'MACOSX_DEPLOYMENT_TARGET': '11.0',
                'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11',
                'OTHER_CFLAGS': [
                    "-fPIC",
                ]
              },
              "dependencies": [
                "<!@(node -p \"require('node-addon-api').gyp\")"
              ],
              "include_dirs": [
                "pkg/mac/build-pulsar/install/include"
              ],
            }],
            ['OS=="win"', {
              "defines": [
                "_HAS_EXCEPTIONS=1"
              ],
              "msvs_settings": {
                "VCCLCompilerTool": {
                  "ExceptionHandling": 1
                },
              },
              "include_dirs": [
                "<(pulsar_cpp_dir)\include",
              ],
              "libraries": [
                "-l<(pulsar_cpp_dir)\\lib\Release\pulsar.lib"
              ],
              "dependencies": [
                "<!(node -p \"require('node-addon-api').gyp\")"
              ],
              "copies": [
                {
                  "destination": "<(PRODUCT_DIR)",
                  "files": [
                    "<(pulsar_cpp_dir)\\lib\Release\pulsar.dll",
                    "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libcurl.dll",
                    "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libprotobuf.dll",
                    "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libssl-1_1-x64.dll",
                    "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libcrypto-1_1-x64.dll",
                    "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\dl.dll",
                    "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\snappy.dll",
                    "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\zlib1.dll",
                    "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\zstd.dll",
                  ]
                }
              ]
            }, {  # 'OS!="win"'
              "dependencies": [
                "<!@(node -p \"require('node-addon-api').gyp\")"
              ],
              "libraries": [
                 "../pkg/lib/libpulsarwithdeps.a"
              ],
            }]
          ]
        },
        {
          "target_name": "action_after_build",
          "type": "none",
          "dependencies": [ "<(module_name)" ],
          "copies": [
            {
              "files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
              "destination": "<(module_path)"
            }
          ]
        }
      ]
    }
    

  2. changed the title [-]The '--target_arch=' parameter does not work[/-] [+]The '--target_arch' parameter does not work[/+] on Oct 21, 2022
  3. cclauss commented on Apr 14, 2024

    @cclauss
    Collaborator

    For support of Node.js > v17, see the workaround:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions