Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
771 views
in Technique[技术] by (71.8m points)

linker - How to link and package external library with node-gyp for electron

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:

  1. Run npm run export-mac
  2. 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.
  3. 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
  4. Click the single button in the UI and check the terminal output
question from:https://stackoverflow.com/questions/65898881/how-to-link-and-package-external-library-with-node-gyp-for-electron

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...