链接到 Node.js 中包含的库
【Linking to libraries included with 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:】
- 当
node-gyp运行时,它会检测 Node.js 的具体发布版本,并下载完整的源代码压缩包或仅下载头文件。如果下载了完整的源代码,插件将可以完全访问 Node.js 的所有依赖。然而,如果只下载了 Node.js 头文件,则只能使用 Node.js 导出的符号。 node-gyp可以使用指向本地 Node.js 源代码镜像的--nodedir标志来运行。使用此选项,插件将可以访问完整的依赖集合。