building native modules for electron
I encounter this err when running electron app:
dyld: Symbol not found: __ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeE Referenced from: node_modules/keccak/build/Release/keccak.node Expected in: flat namespace
It looks daunting at first, and simply searches do not get you desired solutions. But turns out, you just need the right keywords.
It can be inferred that keccak.node is a native (i.e. platform native code, probably compiled from C++, and the binary will be different for different OSes) binding. It sees node version x.x.x, your local env (e.g. macOS), so it builds a version of that native module for you. It will run that from js code (i.e. Foreign function interface), and hope for the best.
It’s reasonable except that the native module is built for macOS + node but running in Electron. It needs to be bulit specifically for Electron. So now we have the right keywords:
And Electron actually has complete instructions for it that just works: https://electronjs.org/docs/tutorial/using-native-node-modules