使用#ifndef中断节点gyp模块

Using #ifndef breaks node-gyp module

本文关键字:gyp 模块 节点 中断 #ifndef 使用      更新时间:2023-10-16

我正在使用C++node-gyp编写一个node.js模块,但当我修复了所有错误时,比如在这个问题中,其中包括通过添加来消除冗余声明

#ifndef BUILDING_NODE_EXTENSION

#endif  

到我的文件。然后我得到错误

module.js:356
  Module._extensions[extension](this, filename);
                               ^
Error: Symbol graph_module not found.
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/home/project/test.js:1:75)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

但当我删除它们时,一切都很好,相反,我只收到像这样的编译器警告

  CXX(target) Release/obj.target/graph/graph/addon.o
../graph/addon.cc:2:9: warning: 'BUILDING_NODE_EXTENSION' macro redefined
#define BUILDING_NODE_EXTENSION

我不明白为什么会这样,如果可能的话,我想去掉编译器警告。有什么想法吗?

看起来您忘记使用NODE_MODULE宏,或者绑定中模块的名称与NODE_MODULE 中使用的名称不匹配

要消除编译器警告,请尝试替换

#define BUILDING_NODE_EXTENSION

带有

#define BUILDING_NODE_EXTENSION 1