Bundling shared library: “cannot open shared object file: No such file or directory“
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.7k
- Forks
- 1.9k
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 5
Description
Hi,
Apologies for opening an issue but after days of scouring the internet and previous issues I am no further, as im not sure whether the issue is config related/expected behaviour/something else.
I’ve built a library which uses Libsodium in the NAPI codebase and all works well. However, I find that I cannot run my module on machines which don't already have LibSodium installed (Mac and Linux). Windows is currently fine as I copy over the DLL.
I was under the impression that the LibSodium library is copied into the generated .node binary. Is this supposed to happen?
Focusing just on Linux (Ubuntu), I have tried multiple methods for installing LibSodium and even tried building from source to isolate whether it is the LibSodium library itself or my NAPI codebase. It appears to be the latter.
Questions:
- Whilst I’ve tried linking to both the static (.a) and shared (.so) library I cannot get them to embed within the binary, have I missed something in my binding.gyp?
- Surely I should not need to ask my end users to install each dependency prior to using my resultant application? (Eventually this NAPI library will be used in an Electron app)
- How do I configure node-gyp to bundle the library so it can be used on machines where the library is not preinstalled?
So to conclude, I'd be most grateful for any assistance on this.
I am receiving the following error on machines where the LibSodium library is not currently installed:
node:internal/modules/cjs/loader:1161
return process.dlopen(module, path.toNamespacedPath(filename));
^
Error: libsodium.so.18: cannot open shared object file: No such file or directory
My binding.gyp:
{
"targets": [
{
"target_name": "Native",
"sources": [
"./lib/module.cc"
],
"cflags": ["-w", "-fpermissive", "-fPIC"],
'include_dirs': [
"<!@(node -p \"require('node-addon-api').include\")"
],
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
'conditions': [
['OS=="linux"', {
'libraries': [ '-lsodium' ],
'defines': [
'SODIUM_STATIC=1',
]
}],
### Tried directly linking to include headers and shared library object
# ["OS=='linux'", {
# "include_dirs": [
# "/usr/include/sodium"
# ],
# "libraries": [
# '-L/usr/lib/x86_64-linux-gnu/libsodium.so'
# ]
# }],
### Tried directly linking to include headers and static library(?) .a file, then copy it to the Release folder (hoping it would be magically linked)
# ["OS=='linux'", {
# "include_dirs": [
# "<(module_root_dir)/lib/libs/sodium/linux/include"
# ],
# "libraries": [
# "<(module_root_dir)/lib/libs/sodium/linux/lib/x86_64-linux-gnu/libsodium.a"
# ],
# "copies": [
# {
# "destination": "<(module_root_dir)/build/Release/",
# "files": [
# "<(module_root_dir)/lib/libs/sodium/linux/lib/x86_64-linux-gnu/libsodium.a"
# ]
# }
# ]
# }],
### Tried directly linking to include headers and shared (.so) file, then copy it to the Release folder (hoping it would be magically linked)
# ["OS=='linux'", {
# "include_dirs": [
# "/usr/include/sodium/include"
# ],
# "libraries": [
# "/usr/lib/x86_64-linux-gnu/libsodium.so"
# ],
# "copies": [
# {
# "destination": "<(module_root_dir)/build/Release/",
# "files": [
# "/usr/lib/x86_64-linux-gnu/libsodium.so"
# ]
# }
# ]
# }],
### MAC AND WINDOWS CONFIG OMITTED
]
}
]
}
How I install LibSodium:
# Apt package manager
- apt-get update
- apt-get install -y libsodium-dev
# From source
BUILD LIBSODIUM
- wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz
- tar -xvf libsodium-1.0.18-stable.tar.gz
- cd libsodium-stable
- ./configure
- make && make check
- make install
- ldconfig
-
Node Version: Node v14.14.0 npm 6.14.8
-
Platform: Darwin Ravs-MacBook-Pro-2.local 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64
-
Compiler:
Apple clang version 12.0.0 (clang-1200.0.32.21)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin -
Module: NAPI library which uses LibSodium
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the binding.gyp shown in the issue, especially the Linux libraries and conditions, and review node-gyp's documentation for native-library linking and packaging. Determine whether bundling a shared Libsodium dependency is supported or requires consumer-side packaging, then document the supported configuration and verify it on Linux and macOS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, nodejs
- Domain
- build-system, devtools
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100