链接到 Node.js 自带的库
Node.js 使用静态链接库,例如 V8、libuv 和 OpenSSL。
所有插件都需要链接到 V8,也可以链接到任何其他依赖项。
通常,这就像包含适当的 #include <...>
语句(例如 #include <v8.h>
)一样简单,node-gyp
将自动定位适当的头文件。
但是,有一些注意事项需要注意:
-
当
node-gyp
运行时,它会检测 Node.js 的特定发布版本并下载完整的源代码压缩包或仅下载头文件。 如果下载了完整的源代码,插件将可以完全访问完整的 Node.js 依赖项集。 但是,如果只下载 Node.js 头文件,则只有 Node.js 导出的符号可用。 -
node-gyp
可以使用指向本地 Node.js 源镜像的--nodedir
标志运行。 使用此选项,插件将可以访问完整的依赖项集。
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.