electron / rebuild

Package to rebuild native Node.js modules against the currently installed Electron version
MIT License
1.02k stars 175 forks source link

Failed to build addon for electron with libc++ #915

Open dogeFu opened 2 years ago

dogeFu commented 2 years ago

My addon use function from STL,I want to run it in electron. so I need to rebuild it with libc++. Here is how I use:

electron-rebuild -f --use-electron-clang true -v 15.3.0

Failed log:

rebuilding addon with args [
  'node',
  'node-gyp',
  'rebuild',
  '/p:CLToolExe=clang-cl.exe',
  '/p:CLToolPath=C:\\Users\\Administrator\\.electron-gyp\\15.3.0-clang\\bin',
  '--runtime=electron',
  '--target=15.3.0',
  '--arch=x64',
  '--dist-url=https://www.electronjs.org/headers',
  '--build-from-source',
  '--silent'
]
- Building module: addon, Completed: 0在此解决方案中一次生成一个项目。若要启用并行生成,请添加“-m”开关。
/ Building module: addon, Completed: 0  addon.cc
- Building module: addon, Completed: 0C:\Users\Administrator\.electron-gyp\15.3.0\include\node\v8.h(1684,55): warning C4996: 'v8::Module::ResolveCallback': Use ResolveModuleCallback [D:\Cocos\addo
n\build\binding.vcxproj]
C:\Users\Administrator\.electron-gyp\15.3.0\include\node\v8.h(8724,7): warning C4996: 'v8::HostImportModuleDynamicallyCallback': Use HostImportModuleDynamical
lyWithImportAssertionsCallback instead [D:\Cocos\addon\build\binding.vcxproj]
| Building module: addon, Completed: 0  win_delay_load_hook.cc
- Building module: addon, Completed: 0    正在创建库 D:\Cocos\addon\build\Release\binding.lib 和对象 D:\Cocos\addon\build\Release\binding.exp
addon.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingStore(voi
d)" (__imp_?GetBackingStore@ArrayBuffer@v8@@QEAA?AV?$shared_ptr@VBackingStore@v8@@@std@@XZ) [D:\Cocos\addon\build\binding.vcxproj]
D:\Cocos\addon\build\Release\binding.node : fatal error LNK1120: 1 个无法解析的外部命令 [D:\Cocos\addon\build\binding.vcxproj]
× Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'D:\Cocos\addon'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".

Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1

Error: node-gyp failed to rebuild 'D:\Cocos\addon'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".
Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1

    at NodeGyp.rebuildModule (C:\Users\Administrator\AppData\Roaming\npm\node_modules\electron-rebuild\lib\src\module-type\node-gyp.js:110:19)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async ModuleRebuilder.rebuildNodeGypModule (C:\Users\Administrator\AppData\Roaming\npm\node_modules\electron-rebuild\lib\src\module-rebuilder.js:94:9)
    at async Rebuilder.rebuildModuleAt (C:\Users\Administrator\AppData\Roaming\npm\node_modules\electron-rebuild\lib\src\rebuild.js:226:9)
    at async Rebuilder.rebuild (C:\Users\Administrator\AppData\Roaming\npm\node_modules\electron-rebuild\lib\src\rebuild.js:184:17)
    at async C:\Users\Administrator\AppData\Roaming\npm\node_modules\electron-rebuild\lib\src\cli.js:154:9

Here is the demo: binding.gyp:

{
  "targets": [
    {
      "target_name": "binding",
      "sources": [ "addon.cc" ]
    }
  ]
}

addon.cc:

#include <tchar.h>
#include <node.h>

namespace demo {

using v8::Exception;
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Number;
using v8::Object;
using v8::String;
using v8::Value;

// This is the implementation of the "add" method
// Input arguments are passed using the
// const FunctionCallbackInfo<Value>& args struct
void Method(const FunctionCallbackInfo<Value>& args) {
    Isolate* isolate = args.GetIsolate();
    v8::Local<v8::ArrayBuffer> jsobj   = v8::ArrayBuffer::New(isolate, 10);
    memset(jsobj->GetBackingStore()->Data(), 0, 10);//has linking error
    args.GetReturnValue().Set(jsobj);
}

void Initialize(Local<Object> exports) {
    NODE_SET_METHOD(exports, "hello", Method);
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)

}  // namespace demo
dogeFu commented 2 years ago

@MarshallOfSound I notice that you have a pull request about libc++ support #431 #434 , Can you help me?