Recent

Author Topic: How to load dylib for fpwebview demos?  (Read 879 times)

Cascade

  • New Member
  • *
  • Posts: 22
How to load dylib for fpwebview demos?
« on: October 25, 2024, 05:49:50 pm »
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?
« Last Edit: October 25, 2024, 06:29:29 pm by Cascade »

TRon

  • Hero Member
  • *****
  • Posts: 3618
Re: How to load dylib for fpwebview demos?
« Reply #1 on: October 26, 2024, 08:22:55 am »
Any 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).

Quote
How 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).
« Last Edit: October 26, 2024, 08:46:44 am by TRon »
This tagline is powered by AI

PierceNg

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
Re: How to load dylib for fpwebview demos?
« Reply #2 on: October 26, 2024, 03:47:26 pm »
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.
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][+][-]
  1. ./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

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
Re: How to load dylib for fpwebview demos?
« Reply #3 on: October 28, 2024, 02:45:31 am »
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

  • Sr. Member
  • ****
  • Posts: 394
    • SamadhiWeb
Re: How to load dylib for fpwebview demos?
« Reply #4 on: October 28, 2024, 09:22:32 am »
Also tested working on aarch64 macOS Sonoma. I've merged the fixes into master: https://github.com/PierceNg/fpwebview

Cascade

  • New Member
  • *
  • Posts: 22
Re: How to load dylib for fpwebview demos?
« Reply #5 on: November 05, 2024, 01:38:11 pm »
Oh wow - thank you. I have just downloaded a zip of the master branch.

Quote
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.

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.

« Last Edit: November 05, 2024, 01:50:36 pm by Cascade »

Cascade

  • New Member
  • *
  • Posts: 22
Re: How to load dylib for fpwebview demos?
« Reply #6 on: November 05, 2024, 01:56:00 pm »
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

  • Hero Member
  • *****
  • Posts: 3618
Re: How to load dylib for fpwebview demos?
« Reply #7 on: November 06, 2024, 01:12:31 am »
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.
This tagline is powered by AI

Cascade

  • New Member
  • *
  • Posts: 22
Re: How to load dylib for fpwebview demos?
« Reply #8 on: November 06, 2024, 10:41:10 pm »
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

 

TinyPortal © 2005-2018