首页 > 解决方案 > 模块没有自行注册。使用使用 cmake-js 编译的自定义构建 c++ 节点模块的电子应用程序

问题描述

在一个项目上工作。为node构建了一个C++模块,用cmake编译。我尝试在我的主电子应用程序中使用该模块,但它出错了。

在这里用最小的 repo 复制它:https ://github.com/Aerrus/electronMinimal

 App threw an error during load
Error: Module did not self-register.
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:160:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:722:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:160:31)
    at Module.load (internal/modules/cjs/loader.js:602:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:541:12)
    at Function.Module._load (internal/modules/cjs/loader.js:533:3)
    at Module.require (internal/modules/cjs/loader.js:640:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at bindings     (C:\Users\xxx\electronMinimal\mods\node_modules\bindings\bindings.js:112:48)
at Object.<anonymous> (C:\Users\xxx\electronMinimal\mods\index.js:1:188)

已经看到很多关于重建它的线程,确保我构建它时的节点版本是相同的,等等。他们都没有改变任何东西。

标签: c++node.jsnpmcmakeelectron

解决方案


如果您使用的是电子 v4.0,请查看此内容。我希望它有所帮助,因为这就是我解决问题的方式

使用 cmake-js 向 cmakelist 添加延迟钩子


推荐阅读