I created a native OCR module using N-API (node-addon-api) with bindings to tesseract OCR.
My intention is to get native OCR working under electron. I basically checked all the npm packages related to OCR and they all don't work with electron. And here is my own test project based on electron, which uses my node-native-ocr module: https://github.com/stoefln/electron-ocr
My problem: I don't manage to package all the dependencies when bundling electron. Or there seems to be a problem with the way I do it, because I am currently getting this error when running the electron project in production:
dyld: Symbol not found: _fmemopen Referenced from: /Volumes/Shared Folders/Downloads/Electron OCR.app/Contents/Resources/app/node_modules/node-native-ocr/build/Release/dependencies/liblept.5.dylib Expected in: /usr/lib/libSystem.B.dylib
The way I am currently trying to package: The .node file which is generated depends on tesseract (built with brew) which depends on a lot of other libraries installed on the system.
What I came up with is a script which recursively reads dependencies (otool -l
), copies them into the .node folder and changes the link (install_name_tool -change ...
) to point to the copied dylib file.
I am not even sure if that's the right way of doing it. Shouldn't the node-gyp linker take care of linking AND packaging everything? Here is somebody asking basically the same question: https://github.com/nodejs/node-gyp/issues/2258
More information if you want to reproduce my problem:
- Run
npm run export-mac
- Copy the .app file to some other machine, to make sure it does not use the libararies in the system and only the ones which are packaged.
- Start the app via the command line (otherwise you won't see the error):
./your_path_to_the_app_file/Electron\ OCR.app/Contents/MacOS/Electron\ OCR
- Click the single button in the UI and check the terminal output