链接到 Node.js 自带的库
Node.js 使用静态链接库,例如 V8、libuv 和 OpenSSL。
所有插件都需要链接到 V8,也可以链接到任何其他依赖项。
通常,这就像包含适当的 #include <...>
语句(例如 #include <v8.h>
)一样简单,node-gyp
将自动定位适当的头文件。
但是,有一些注意事项需要注意:
Node.js uses statically linked libraries such as V8, libuv and OpenSSL. All
addons are required to link to V8 and may link to any of the other dependencies
as well. Typically, this is as simple as including the appropriate
#include <...>
statements (e.g. #include <v8.h>
) and node-gyp
will locate
the appropriate headers automatically. However, there are a few caveats to be
aware of:
-
When
node-gyp
runs, it will detect the specific release version of Node.js and download either the full source tarball or just the headers. If the full source is downloaded, addons will have complete access to the full set of Node.js dependencies. However, if only the Node.js headers are downloaded, then only the symbols exported by Node.js will be available. -
node-gyp
can be run using the--nodedir
flag pointing at a local Node.js source image. Using this option, the addon will have access to the full set of dependencies.