我正在编写一个依赖OpenGL(glfw
)的nodejs插件。它编译成功,但是当我尝试在节点中使用它时,出现错误The specified module could not be found
。
这是插件C ++代码中有问题的部分:
#include <glfw/glfw3.h>
if(glfwInit()) {
printf("glfw init success");
}
else {
printf("glfw init failed");
}
使用此插件,它会编译,但会导致节点错误。没有它,它就可以编译并运行。
这是我的binding.gyp:
{
"targets": [
{
"target_name": "engine","sources": [
"addon/addon.cc"
],"libraries": [
"<(module_root_dir)/addon/lib/gl/glfw3dll.lib"
],"include_dirs": [
"addon/lib","<!@(node -p \"require('node-addon-api').include\")"
],'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],}
]
}
以及插件文件结构:
addon
lib
glfw
glfw3.dll
glfw3.h
glfw3.lib
glfw3dll.lib
glfw3native.h
opengl32.lib
addon.cc
编辑: 新的binding.gyp:
{
"targets": [
{
"target_name": "engine","libraries": [
"-lglfw3dll","-lopengl32","-L<module_root_dir)/lib/glfw","-Wl,-rpath,\$$ORIGIN/../../lib",],'<!@(node -p "require(\'node-addon-api\').include")'
],}
]
}