[英]how to add dependence to static library in binding.gyp node-gyp for node.js extension
I have a simple binding.gyp file for building my node.js extension. 我有一个简单的binding.gyp文件,用于构建我的node.js扩展。 I want to change the linking method of the library "mylib" and link it statically instead of using shared library. 我想更改库“mylib”的链接方法并静态链接它而不是使用共享库。
{
"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" ]
}
]
}
The static and shared versions of mylib are in the same directory: mylib的静态和共享版本位于同一目录中:
# ls /home/admin/MyLib/Library/binaries/linux/Release
libmylib.a libmylib.so
I want to link statically to avoid library installing/loading issues. 我想静态链接以避免库安装/加载问题。
Just add the path of static .a or .so file in the "libraries" section, 只需在“libraries”部分添加静态.a或.so文件的路径,
"libraries": [ "/usr/local/lib/libnetfilter_queue.so.1.3.0" ] “libraries”:[“/ usr / local / lib / libnetfilter_queue.so.1.3.0”]
You could have node-gyp insert the path for you with the built in variable module_root_dir
If I interpret your code correctly, changing your libraries
to eg: 您可以使用内置变量module_root_dir
为node-gyp插入路径如果我正确解释您的代码,将libraries
更改为:
"libraries": [
"-lmylib",
"-L<(module_root_dir)/../Library/binaries/linux/Release"
],
might do the trick. 可能会做的伎俩。 Though I'm not sure if it will link with the .a
or .so
version, to specify that you could try: 虽然我不确定它是否会链接.a
或.so
版本,但要指明您可以尝试:
"libraries": [
"<(module_root_dir)/../Library/binaries/linux/Release/libmylib.a"
],
with out the -L
prefix and -lmylib
. 没有 -L
前缀和-lmylib
。 Further more, I'm a bit unsure if you're allowed to traverse above the root directory though. 此外,我有点不确定你是否被允许遍历根目录。 I have not tested using anything above the module root directory before. 我之前没有测试过使用模块根目录之上的任何内容。 Other than that you should be good to go. 除此之外你应该好好去。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.