How to load dylib for fpwebview demos? lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- Cascade · 2024-10-25 15:49 I’d like to run the demo projects provided with the fpwebview library, but so far I can’t get them to run.  For example, the demo ‘lclembed’ compiles successfully (so the compiler is finding the dylib OK for linking), but when the app is run the dylib does not seem to load. If I run from the Lazarus IDE, I get a SIGABRT error message.  If I run by double clicking the executable file directly in Finder, then terminal opens and displays the following output: Code: [Select]/Users/ … /FPWebView/demo/lclembed/lclembed ; exit; dyld: Library not loaded: libwebview.dylib   Referenced from: /Users/ … /FPWebView/demo/lclembed/lclembed   Reason: image not found zsh: abort      /Users/ … /FPWebView/demo/lclembed/lclembed [Process completed] I’m on macOS Catalina 10.15.7, so I’ve tried different versions of the dylib, including one that indicates it was built on Catalina (10.15) Any ideas what the issue might be? How can I build the dylib myself? ---------------------------------------------------------------------- TRon · 2024-10-26 06:22 Quote from: Cascade on October 25, 2024, 05:49:50 pmAny ideas what the issue might be? That you are able to build the project is not the same as at runtime loading the library.. In layman terms: File not found. Now, my knowledge on macOS is nil but on Linux I would have to add the directory where the library is located to the "library path" (or when the library was installed with the package manager, install the dev- package of that specific library in case it exist) . I have no idea how either of these would have to be done on/for MacOS (* see edit). Note that you might also be able to produce this message when one of the dependencies (from libwebview) cannot be loaded (which effectively fails loading libwebview itself). QuoteHow can I build the dylib myself? No idea tbh but also not required. * edit: see wiki (turns out you can do similar on MacOS as for Linux. Please read the whole page as well, especially the package creation with Lazarus in case that has your interest). ---------------------------------------------------------------------- PierceNg · 2024-10-26 13:47 Quote from: Cascade on October 25, 2024, 05:49:50 pmI’d like to run the demo projects provided with the fpwebview library, but so far I can’t get them to run.  For example, the demo ‘lclembed’ compiles successfully (so the compiler is finding the dylib OK for linking), but when the app is run the dylib does not seem to load. I’m on macOS Catalina 10.15.7, so I’ve tried different versions of the dylib, including one that indicates it was built on Catalina (10.15) The script macbuild.sh copies the pre-built dylib before building the lclembed executable. Once built, try running it from a shell prompt in the demo/lclembed directory: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ./lclembed My x86_64 MBP now runs Monterey, no longer Catalina. Just tested and this procedure still works. As for double-clicking on the app in Finder, it doesn't work for now, because of macOS-isms about @rpath. I need to poke at this a bit more with otool and install_name_tool to fix. ---------------------------------------------------------------------- PierceNg · 2024-10-28 01:45 Please try 'apr2024' branch. lclembed.app is now runnable by double clicking in Finder and also by "open lclembed.app" at the shell prompt. Tested on my x86_64 Monterey MBP: It works on my computer.TM Build the app by running macbuild.sh and macpostbuild.sh in turn. Curiously I wasn't able to build the app from within Lazarus (3.6) IDE, to be investigated. I also have an aarch64 MBP running Sonoma to be tested. Key changes: - Copying libwebview.dylib and web content into the app bundle using the script macpostbuild.sh. - Accounting for macOS-isms like rpath and installed names. Note the setup misses some best practices: - The dylib ought to be wrapped into a framework and installed in the Frameworks directory within the app bundle. - The web content ought to be in the Resources directory within the app bundle. ---------------------------------------------------------------------- PierceNg · 2024-10-28 08:22 Also tested working on aarch64 macOS Sonoma. I've merged the fixes into master: https://github.com/PierceNg/fpwebview ---------------------------------------------------------------------- Cascade · 2024-11-05 12:38 Oh wow - thank you. I have just downloaded a zip of the master branch. QuoteBuild the app by running macbuild.sh and macpostbuild.sh in turn. Curiously I wasn't able to build the app from within Lazarus (3.6) IDE, to be investigated. Interestingly, I had the opposite problem: OK building the lclembed app from within the Lazarus IDE (3.99) - but not via macbuild.sh (lazbuild not found). This one definitely gets further - and gives an informative error message.  The issue is looking like security on my system.  The dylib is not loading because the developer can't be verified (screenshot attached). I had a go at building the web view dylib myself, hoping my system would then accept it, but the resulting dylib is only 16KB - so I think I got something wrong there. ---------------------------------------------------------------------- Cascade · 2024-11-05 12:56 When running from terminal (not using the app bundle) I now get more detailed information about the issue: Code: [Select]/Users/ … /FPWebView/demo/lclembed/lclembed ; exit; dyld: Library not loaded: @executable_path/libwebview.dylib   Referenced from: /Users/ … /FPWebView/demo/lclembed/lclembed   Reason: no suitable image found.  Did find: /Users/ … /FPWebView/demo/lclembed/libwebview.dylib: code signature in (/Users/ … /FPWebView/demo/lclembed/libwebview.dylib) not valid for use in process using Library Validation: library load disallowed by system policy /Users/ … /FPWebView/demo/lclembed/libwebview.dylib: stat() failed with errno=1 ---------------------------------------------------------------------- TRon · 2024-11-06 00:12 Error 1 = EPERM (permission error) Something seems off in either the application bundle (signing) or an overall policy (might be as simple as library located in the wrong place e.g. library not allowed to be loaded from that location). iow, I have no idea of the cause and how to approach as I lack the knowledge. ---------------------------------------------------------------------- Cascade · 2024-11-06 21:41 Thanks TRon - it's good to know what that error code means. I wonder whether I need to add some kind of permission to the plist.info file in the app bundle? Code: [Select]libwebview.dylib: code signature ... not valid for use in process using Library Validation: library load disallowed by system policy That message looks particularly significant.  Either the system doesn't like the code signature that is on the dylib file, or maybe it isn't currently signed, so the system refuses to load the library? I found some related information, which seems to indicate a kind of workaround, by granting the app an entitlement to bypass Library Validation - but I don't fully understand it, nor the risks or implications.  Here's a link in case it helps shed some light: Apple Developer - Entitlement to disable library validation