I did not find in the documentation how to add static library to binding.gyp?
I've successfully compiled my node.js extension with reference to the shared library as follows:
{
"targets": [
{
"target_name": "myext",
"sources": [
"code/main.cpp",
"code/load.cpp",
"include/load.h"
],
"include_dirs": [
"include", "../Library/include"
],
"libraries": [
"-lmylib", "-L/home/admin/MyLib/Library/binaries/linux/Release"
],
"cflags!": [ "-fno-exceptions" ],
"cflags": [ "-std=c++11" ],
"cflags_cc!": [ "-fno-exceptions" ]
}
]
}
and now want to add static version of the library to the extension to avoid libray loading issues. Is this possible?
Thanks!
Just specify the path the to the static .a file in the "libraries" section:
"libraries": [ "/usr/local/lib/mylib.a" ]
thanks, the answer is helpful
I have a similar problem,
my static library is in "deps/csk2". I got
"g++: error: ./deps/csk2/libcsk2_linux_x64.a: No such file or directory"
But if I change the library path to absolute path("/home/vimos/Public/git/lm-redis/klm/node-sri/deps/csk2/libcsk2_<(OS)_x64.a"), no error reports.
Why?
Thank you for your answer @TooTallNate . It's really helpful.
@Vimos , you can write like this: "libraries": [ "-Wl,-rpath, mylib.a" ] . This can work.
if i want to link shared library then i need to just replace .a with .so or anything else do i need to do?
@Embedded4development 'libraries': ['-L/path/to/dir', '-lfoo'] if the shared object is called libfoo.so. The -L switch is only necessary when it's not in a standard location. You may also want to pass -Wl,-rpath in that case.
@bnoordhuis
if i have multiple libraries then what would be perfect syntax to map library name & respective path?
@Embedded4development 'libraries': ['-lfoo', '-lbar', '-lbaz'] - add search directories and rpaths if necessary.
@bnoordhuis Thanks for useful response..
I am compiling on Windows and as I saw the file get's compiled but the static library is not embedded on the code, is there a way for the generated .node file to have the static library embbedded on it's code? So that the client does not need to have a dll.
@drFabio If you have a dll, it's not a static library.
@bnoordhuis I have a .lib but the generated .node file when inspected with dependency walker says it's needing the dll.
It compiles without error , but when in use on the windows machine if the user does not have a registered dll it does not work.
@drFabio Where does the lib file come from? Who or what produces it?
It is libeay32.lib I use the lib that comes from the installer in from
http://slproweb.com/products/Win32OpenSSL.html that is recommended on
https://github.com/nodejs/node-gyp/wiki/Linking-to-OpenSSL
On Aug 3, 2016 5:00 PM, "Ben Noordhuis" [email protected] wrote:
@drFabio https://github.com/drFabio Where does the lib file come from?
Who or what produces it?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/nodejs/node-gyp/issues/328#issuecomment-237353921,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACg5b6ZThBFR7MT4WMwVc7h2n334ZmVHks5qcPNjgaJpZM4A_W2w
.
At a guess, it sounds like the lib file is just glue code for the dll. In that case you're SOL.
This whole time I was assuming this was node-gyp default behaviour.
Everything makes sense now. Thanks a ton!
On Aug 3, 2016 5:53 PM, "Ben Noordhuis" [email protected] wrote:
At a guess, it sounds like the lib file is just glue code for the dll. In
that case you're SOL.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/nodejs/node-gyp/issues/328#issuecomment-237369801,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACg5b-g9AA45KyRNgHuRWyMhlkAHEFupks5qcP-7gaJpZM4A_W2w
.
How to add dependence of shared_library in binding.gyp?
I have .node file of my C++ project and I want to refer this .node file in its Unit test project.
But I am unable to link .node/ .dll file in binding.gyp file of my Unit Test project.
If I build my C++ project with static library, I am able to execute my unit tests sucessfully.
Instead of
"libraries": ["-lmylib", "-L/home/admin/MyLib/Library/binaries/linux/Release"]
you could say
"libraries": ["-lmylib", "-L'
assuming your libmylib.so file is in the same directory as binding.gyp.
For making the path relative, just use module_root_dir, which is a variable exposed by node-gyp.
"libraries": ["<(module_root_dir)/......"]
-Wl,-rpath,... did not work for me, causing symbol lookup errors.
What is wrong in below code? It is throwing linking error.
'targets': [
{
'target_name': 'abc',
'type': 'shared_library',
'conditions': [],
'dependencies': [],
'libraries':[
'mylib.a'
],
'mac_framework_dirs' : [
],
'all_dependent_settings': {},
},
Just specify the path the to the static .a file in the "libraries" section:
"libraries": [ "/usr/local/lib/mylib.a" ]
Does this make it so in node you can call the function from mylib.a? If so, what would that formatting look like?
Most helpful comment
Just specify the path the to the static .a file in the "libraries" section: