I use SwiftPM to wrapper the Tesseract C library by official guide requiring-system-libraries. And it works on my mac device. However, the archived App crash on the other device without the Tesseract installation.
I notice the SwiftPM does not contain dylib so the Xcode does not embed the libraries. After adding the liblept.dylib and libtesseract.dylib under the /usr/local/lib/ to Xcode - App Target - "Frameworks, Libraries, and Embedded Content" section. The app size looks normal but still have that error message on other people device.
Termination Reason: DYLD, [0x1] Library missing
Application Specific Information:
dyld: launch, loading dependent libraries
Dyld Error Message:
Library not loaded: /usr/local/opt/tesseract/lib/libtesseract.4.dylib
Referenced from: /Users/USER/Downloads/ImageReader.app/Contents/MacOS/ImageReader
Reason: image not found
The dylib is already embedded under the ./Content/Frameworks/. How to make the app search and use it?
You need to use the install_name_tool (probably in a post-build runscript) to change the dyld path embedded in ImageReader during the build phase to using rpath which would cause the dyld linker at runtime find the dylibs. Man pages on dyld and install_name_tool explain the concept.
If you run otool on your executable (ImageReader), you will list the paths of the dylibs that have been linked into the image. I thinks it is either otool -L or otool -D.