Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve issue with relative paths during linking #3128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Dw9
Copy link

@Dw9 Dw9 commented Feb 13, 2025

Checklist
  • npm install && npm run lint && npm test passes
  • tests are included
  • documentation is changed or added
  • commit message follows commit guidelines
Description of change

hi~ I encountered an issue with library resolution when configuring binding.gyp. Below are the details of my configuration and the compilation process.

node-gyp correctly handled the header file directory, but the library directory wasn't processed during the linking phase. I am new to Node.js, and I would appreciate any feedback or corrections if something is wrong.

@Dw9
Copy link
Author

Dw9 commented Feb 13, 2025

image

@Dw9
Copy link
Author

Dw9 commented Feb 13, 2025

My binding.gyp configuration

{
  "targets": [
    {
      "target_name": "addon",
      "cflags!": [ "-fno-exceptions -fPIC -fWunused-variable -fWint-to-pointer-cast]" ],
      "cflags_cc!": [ "-fno-exceptions -fPIC -fWunused-variable -fWint-to-pointer-cast]" ],
      "sources": [ "addon.cc", "myobject.cc" ],
      "include_dirs": [
        "../3rdpart/include",
        "<!@(node -p \"require('node-addon-api').include\")"
      ],
      "library_dirs" : [
        "../3rdpart/lib"
      ],
      "libraries": [
        "-ltest"
      ],
      'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
    }
  ]
}

@Dw9
Copy link
Author

Dw9 commented Feb 13, 2025

Compilation log

node-addon-api node-gyp build --verbose
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli '/home/zhibo/.nvm/versions/node/v22.13.0/bin/node',
gyp verb cli '/home/zhibo/.nvm/versions/node/v22.13.0/bin/node-gyp',
gyp verb cli 'build',
gyp verb cli '--verbose'
gyp verb cli ]
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /home/zhibo/.cache/node-gyp/22.13.0
gyp verb python /home/zhibo/miniconda3/bin/python3
gyp verb `which` succeeded for `make` /usr/bin/make
gyp verb bin symlinks created symlink to "/home/zhibo/miniconda3/bin/python3" in "/home/zhibo/6_object_wrap/node-test/node-addon-api/build/node_gyp_bins" and added to PATH
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/zhibo/6_object_wrap/node-test/node-addon-api/build'
  g++ -o Release/obj.target/addon/addon.o ../addon.cc '-DNODE_GYP_MODULE_NAME=addon' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DNAPI_DISABLE_CPP_EXCEPTIONS' '-DBUILDING_NODE_EXTENSION' -I/home/zhibo/.cache/node-gyp/22.13.0/include/node -I/home/zhibo/.cache/node-gyp/22.13.0/src -I/home/zhibo/.cache/node-gyp/22.13.0/deps/openssl/config -I/home/zhibo/.cache/node-gyp/22.13.0/deps/openssl/openssl/include -I/home/zhibo/.cache/node-gyp/22.13.0/deps/uv/include -I/home/zhibo/.cache/node-gyp/22.13.0/deps/zlib -I/home/zhibo/.cache/node-gyp/22.13.0/deps/v8/include -I../../3rdpart/include -I/home/zhibo/6_object_wrap/node-test/node-addon-api/node_modules/.pnpm/[email protected]/node_modules/node-addon-api  -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -fno-omit-frame-pointer -fno-rtti -fno-exceptions -fno-strict-aliasing -std=gnu++17 -MMD -MF ./Release/.deps/Release/obj.target/addon/addon.o.d.raw   -c
  g++ -o Release/obj.target/addon/myobject.o ../myobject.cc '-DNODE_GYP_MODULE_NAME=addon' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-D__STDC_FORMAT_MACROS' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DNAPI_DISABLE_CPP_EXCEPTIONS' '-DBUILDING_NODE_EXTENSION' -I/home/zhibo/.cache/node-gyp/22.13.0/include/node -I/home/zhibo/.cache/node-gyp/22.13.0/src -I/home/zhibo/.cache/node-gyp/22.13.0/deps/openssl/config -I/home/zhibo/.cache/node-gyp/22.13.0/deps/openssl/openssl/include -I/home/zhibo/.cache/node-gyp/22.13.0/deps/uv/include -I/home/zhibo/.cache/node-gyp/22.13.0/deps/zlib -I/home/zhibo/.cache/node-gyp/22.13.0/deps/v8/include -I../../3rdpart/include -I/home/zhibo/6_object_wrap/node-test/node-addon-api/node_modules/.pnpm/[email protected]/node_modules/node-addon-api  -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -fno-omit-frame-pointer -fno-rtti -fno-exceptions -fno-strict-aliasing -std=gnu++17 -MMD -MF ./Release/.deps/Release/obj.target/addon/myobject.o.d.raw   -c
  g++ -o Release/obj.target/addon.node -shared -pthread -rdynamic -m64 -L../3rdpart/lib  -Wl,-soname=addon.node -Wl,--start-group Release/obj.target/addon/addon.o Release/obj.target/addon/myobject.o -Wl,--end-group -ltest
/usr/bin/ld: cannot find -ltest: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [addon.target.mk:146: Release/obj.target/addon.node] Error 1
make: Leaving directory '/home/zhibo/6_object_wrap/node-test/node-addon-api/build'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants