How to load a dynamic library that needs another library?
See original GitHub issueHi,
I am new to Node FFI and more generally to native addons. I need to wrap a dynamic library on MacOS (let’s call it libA), which needs to load another dynamic library (libB). This is my project structure:
build/
libA.dylib
libB.dylib
lib/
a.js
lib/a.js
is where I create my wrapper:
// [...]
const addon = ffi.Library("./build/libA.dylib", {
// [...]
});
// [...]
Now when I want to test this, from the project root folder: node ./lib/a.js
. FFI seems to be able to load libA
, but then libB
is not loaded:
Error: Dynamic Linking Error: dlopen(./build/libA.dylib, 2): Library not loaded: @rpath/libB.dylib
Referenced from: /Users/jroy/Workspace/test-node-ffi/build/libA.dylib
Reason: image not found
at new DynamicLibrary (/Users/jroy/Workspace/test-node-ffi/node_modules/ffi/lib/dynamic_library.js:74:11)
at Object.Library (/Users/jroy/Workspace/test-node-ffi/node_modules/ffi/lib/library.js:45:12)
at Object.<anonymous> (/Users/jroy/Workspace/test-node-ffi/lib/a.js:31:19)
at Module._compile (internal/modules/cjs/loader.js:721:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Module.require (internal/modules/cjs/loader.js:657:17)
at require (internal/modules/cjs/helpers.js:22:18)
How am I supposed to handle this? Do I need to copy libB.dylib
somewhere else (I already tried to copy it in lib
and in the project root folder without success)?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6
Top Results From Across the Web
Using a shared library in another shared library - Stack Overflow
Simply use the library like you'd use it in any other application. You don't have to link ...
Read more >4. Dynamically Loaded (DL) Libraries
Dynamically loaded (DL) libraries are libraries that are loaded at times other than during the startup of a program. They're particularly useful for ......
Read more >Shared Libraries: Understanding Dynamic Loading
In this post, I will attempt to explain the inner workings of how dynamic loading of shared libraries works in Linux systems.
Read more >Building And Using Static And Shared "C" Libraries
Loading A Shared Library Using dlopen(); Calling Functions Dynamically Using dlsym() ... that need to copy the library to another directory for some...
Read more >Loading Dynamic Libraries on Mac
On Windows, when an executable needs a dynamic library, it searches for it in a few predefined locations, such as “the same directory...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In my case the solution was fixing the DLL path using ‘path.join’.
const dllFunctions = ffi.Library(path.join(static__, myDll.dll), { // some code });
I have the same problem. I tried to put the dependencies in my System32 folder and it doesn’t work every time.