andy128k / cl-gobject-introspection

BSD 2-Clause "Simplified" License
49 stars 15 forks source link

Problem loading Shared Library #74

Closed jmercouris closed 4 years ago

jmercouris commented 4 years ago

Hi, nice library!

I'm working a little bit with it and I'm able to get the following code to work:

(ql:quickload :cl-gobject-introspection)

(defvar *gtk* (gir:require-namespace "Gtk"))
(defvar *gio* (gir:ffi "Gio"))

(gir:invoke (*gtk* 'init) nil)

(defvar *result* nil)
(defvar *callback-view* nil)
(defvar *callback-label* nil)

(let* ((window (gir:invoke (*gtk* "Window" 'new) (gir:nget *gtk* "WindowType" :toplevel)))
       (box (gir:invoke (*gtk* "Box" 'new) (gir:nget *gtk* "Orientation" :vertical) 0))
       (label (gir:invoke (*gtk* "Label" 'new) "Hello GNU, from lisp!")))
  (gir:invoke (box 'pack-start) label t t 0)
  (gir:invoke (window 'add) box)
  (gir:connect window
           :destroy (lambda (x)
                          (declare (ignore x))
              (gir:invoke (*gtk* 'main_quit))))
  (gir:invoke (window 'show-all))
  (gir:invoke (*gtk* 'main)))

This indicates to me that GTK is properly installed and the type libs are getting properly loaded. The problem arises the moment I try to use a different library:

(ql:quickload :cl-gobject-introspection)

(defvar *gtk* (gir:require-namespace "Gtk"))
(defvar *gio* (gir:ffi "Gio"))

;; FIXME: use gtk-application with activate signal instead of gtk_main
(gir:invoke (*gtk* 'init) nil)

(defvar *result* nil)
(defvar *callback-view* nil)
(defvar *callback-label* nil)

(let* ((webkit (gir:require-namespace "WebKit2"))
       (window (gir:invoke (*gtk* "Window" 'new) (gir:nget *gtk* "WindowType" :toplevel)))
       (box (gir:invoke (*gtk* "Box" 'new)
            (gir:nget *gtk* "Orientation" :vertical) 0))
       (view (gir:invoke (webkit "WebView" 'new))))
  (gir:invoke (box 'pack-start) view t t 0)
  (gir:invoke (window 'add) box)
  (gir:invoke (view 'load-uri) "https://www.gnu.org")
  (gir:connect window :destroy (lambda (x) (gir:invoke (*gtk* 'main_quit))))
  (gir:invoke (window 'show-all))
  (gir:invoke (*gtk* 'main)))

This results in the following condition being raised:

Could not locate webkit_web_view_new: dlopen(@rpath/libjavascriptcoregtk-4.0.18.dylib, 9): image not found
   [Condition of type SIMPLE-ERROR]

Restarts:
 0: [RETRY] Retry EVAL of current toplevel form.
 1: [CONTINUE] Ignore error and continue loading file "/Users/jmercouris/Source/Lisp/giqt/examples/hello-webview.lisp".
 2: [ABORT] Abort loading file "/Users/jmercouris/Source/Lisp/giqt/examples/hello-webview.lisp".
 3: [*ABORT] Return to SLIME's top level.
 4: [ABORT] abort thread (#<THREAD "worker" RUNNING {1004516E63}>)

Backtrace:
  0: ((LAMBDA (&REST GIR::ARGS-IN) :IN GIR::BUILD-FUNCTION))
  1: ((LAMBDA NIL :IN "/Users/jmercouris/Source/Lisp/giqt/examples/hello-webview.lisp"))
  2: (SB-INT:SIMPLE-EVAL-IN-LEXENV (LET* ((WEBKIT #) (WINDOW #) (BOX #) (VIEW #)) (GIR:INVOKE (BOX #) VIEW T T 0) (GIR:INVOKE (WINDOW #) BOX) (GIR:INVOKE (VIEW #) "https://www.gnu.org") (GIR:CONNECT WINDOW..
  3: (EVAL-TLF (LET* ((WEBKIT #) (WINDOW #) (BOX #) (VIEW #)) (GIR:INVOKE (BOX #) VIEW T T 0) (GIR:INVOKE (WINDOW #) BOX) (GIR:INVOKE (VIEW #) "https://www.gnu.org") (GIR:CONNECT WINDOW :DESTROY (LAMBDA # ..
  4: ((LABELS SB-FASL::EVAL-FORM :IN SB-INT:LOAD-AS-SOURCE) (LET* ((WEBKIT #) (WINDOW #) (BOX #) (VIEW #)) (GIR:INVOKE (BOX #) VIEW T T 0) (GIR:INVOKE (WINDOW #) BOX) (GIR:INVOKE (VIEW #) "https://www.gnu...
  5: ((LAMBDA (SB-KERNEL:FORM &KEY :CURRENT-INDEX &ALLOW-OTHER-KEYS) :IN SB-INT:LOAD-AS-SOURCE) (LET* ((WEBKIT #) (WINDOW #) (BOX #) (VIEW #)) (GIR:INVOKE (BOX #) VIEW T T 0) (GIR:INVOKE (WINDOW #) BOX) (G..
  6: (SB-C::%DO-FORMS-FROM-INFO #<CLOSURE (LAMBDA (SB-KERNEL:FORM &KEY :CURRENT-INDEX &ALLOW-OTHER-KEYS) :IN SB-INT:LOAD-AS-SOURCE) {100451B34B}> #<SB-C::SOURCE-INFO {100451B303}> SB-C::INPUT-ERROR-IN-LOAD..
  7: (SB-INT:LOAD-AS-SOURCE #<SB-INT:FORM-TRACKING-STREAM for "file /Users/jmercouris/Source/Lisp/giqt/examples/hello-webview.lisp" {10045193C3}> :VERBOSE NIL :PRINT NIL :CONTEXT "loading")
  8: ((FLET SB-FASL::THUNK :IN LOAD))
  9: (SB-FASL::CALL-WITH-LOAD-BINDINGS #<CLOSURE (FLET SB-FASL::THUNK :IN LOAD) {56410FB}> #<SB-INT:FORM-TRACKING-STREAM for "file /Users/jmercouris/Source/Lisp/giqt/examples/hello-webview.lisp" {10045193C..
 10: ((FLET SB-FASL::LOAD-STREAM :IN LOAD) #<SB-INT:FORM-TRACKING-STREAM for "file /Users/jmercouris/Source/Lisp/giqt/examples/hello-webview.lisp" {10045193C3}> NIL)
 11: (LOAD #P"/Users/jmercouris/Source/Lisp/giqt/examples/hello-webview.lisp" :VERBOSE NIL :PRINT NIL :IF-DOES-NOT-EXIST T :EXTERNAL-FORMAT :DEFAULT)
 --more--

This might lead you to think that I haven't installed libjavascriptcore, however a cursory examination shows that it exists:

  /opt/local/lib/:
  find . \( -iname libjavascriptcoregtk-4.0.18.dylib \) -ls
  8642468553        0 lrwxr-xr-x    1     root             admin                  38 Nov 11 22:23 libjavascriptcoregtk-4.0.18.dylib -> libjavascriptcoregtk-4.0.18.14.7.dylib

  find finished at Fri Dec 13 16:01:16

Additionally the contents of /opt/local/share/gir-1.0:

  /opt/local/share/gir-1.0:
  total used in directory 8360 available 142.1 GiB
  drwxr-xr-x  66 root  admin     2112 Dec 12 15:13 .
  drwxr-xr-x  85 root  admin     2720 Dec 12 15:12 ..
  -rw-r--r--   1 root  admin   765305 Oct  3  2018 Atk-1.0.gir
  -rw-r--r--   1 root  admin   385468 Jul  7 09:04 Atspi-2.0.gir
  -rw-r--r--   1 root  admin     1185 Sep 11 22:07 DBus-1.0.gir
  -rw-r--r--   1 root  admin      797 Sep 11 22:07 DBusGLib-1.0.gir
  -rw-r--r--   1 root  admin    15670 Jan  9  2019 GDesktopEnums-3.0.gir
  -rw-r--r--   1 root  admin   192354 Sep 11 22:07 GIRepository-2.0.gir
  -rw-r--r--   1 root  admin     1122 Sep 11 22:07 GL-1.0.gir
  -rw-r--r--   1 root  admin  2324777 Sep 11 22:07 GLib-2.0.gir
  -rw-r--r--   1 root  admin    13785 Sep 11 22:07 GModule-2.0.gir
  -rw-r--r--   1 root  admin   756165 Sep 11 22:07 GObject-2.0.gir
  -rw-r--r--   1 root  admin    46464 Oct  4  2018 GSSDP-1.0.gir
  -rw-r--r--   1 root  admin   250232 Oct  4  2018 GUPnP-1.0.gir
  -rw-r--r--   1 root  admin    25694 Oct  4  2018 GUPnPIgd-1.0.gir
  -rw-r--r--   1 root  admin  1278587 Oct 17 04:54 Gdk-3.0.gir
  -rw-r--r--   1 root  admin   196860 Oct  1  2018 GdkPixbuf-2.0.gir
  -rw-r--r--   1 root  admin    72262 Oct 17 04:54 GdkX11-3.0.gir
  -rw-r--r--   1 root  admin   178551 Dec 11 16:29 Geoclue-2.0.gir
  -rw-r--r--   1 root  admin  4314168 Sep 11 22:07 Gio-2.0.gir
  -rw-r--r--   1 root  admin   383280 Mar 28  2019 Graphene-1.0.gir
  -rw-r--r--   1 root  admin  2315350 Oct 31 06:21 Gst-1.0.gir
  -rw-r--r--   1 root  admin    17057 Oct 31 06:32 GstAllocators-1.0.gir
  -rw-r--r--   1 root  admin    89599 Oct 31 06:32 GstApp-1.0.gir
  -rw-r--r--   1 root  admin   460229 Oct 31 06:32 GstAudio-1.0.gir
  -rw-r--r--   1 root  admin   600859 Oct 31 06:21 GstBase-1.0.gir
  -rw-r--r--   1 root  admin   175429 Oct 31 06:21 GstCheck-1.0.gir
  -rw-r--r--   1 root  admin    42877 Oct 31 06:21 GstController-1.0.gir
  -rw-r--r--   1 root  admin   481365 Oct 31 06:32 GstGL-1.0.gir
  -rw-r--r--   1 root  admin    19310 Dec 11 16:33 GstInsertBin-1.0.gir
  -rw-r--r--   1 root  admin   236758 Dec 11 16:33 GstMpegts-1.0.gir
  -rw-r--r--   1 root  admin    40052 Oct 31 06:21 GstNet-1.0.gir
  -rw-r--r--   1 root  admin   195560 Oct 31 06:32 GstPbutils-1.0.gir
  -rw-r--r--   1 root  admin   105609 Dec 11 16:33 GstPlayer-1.0.gir
  -rw-r--r--   1 root  admin   269287 Oct 31 06:32 GstRtp-1.0.gir
  -rw-r--r--   1 root  admin   234117 Oct 31 06:32 GstRtsp-1.0.gir
  -rw-r--r--   1 root  admin   205210 Oct 31 06:32 GstSdp-1.0.gir
  -rw-r--r--   1 root  admin    84453 Oct 31 06:32 GstTag-1.0.gir
  -rw-r--r--   1 root  admin   698674 Oct 31 06:32 GstVideo-1.0.gir
  -rw-r--r--   1 root  admin    47186 Dec 11 16:33 GstWebRTC-1.0.gir
  -rw-r--r--   1 root  admin  7161137 Oct 17 04:54 Gtk-3.0.gir
  -rw-r--r--   1 root  admin   163868 Nov 11 21:28 JavaScriptCore-4.0.gir
  -rw-r--r--   1 root  admin   241465 Oct  4  2018 Json-1.0.gir
  -rw-r--r--   1 root  admin   162970 Dec 11 16:30 Nice-0.1.gir
  -rw-r--r--   1 root  admin    34055 Oct 24 06:58 Notify-0.7.gir
  -rw-r--r--   1 root  admin   651930 Oct  1  2018 Pango-1.0.gir
  -rw-r--r--   1 root  admin    40518 Oct  1  2018 PangoCairo-1.0.gir
  -rw-r--r--   1 root  admin    15105 Oct  1  2018 PangoFT2-1.0.gir
  -rw-r--r--   1 root  admin    31675 Oct  1  2018 PangoXft-1.0.gir
  -rw-r--r--   1 root  admin   416896 Oct 12 14:00 Poppler-0.18.gir
  -rw-r--r--   1 root  admin    69453 Oct 29 23:55 Rsvg-2.0.gir
  -rw-r--r--   1 root  admin   335738 Oct 24 07:08 Secret-1.gir
  -rw-r--r--   1 root  admin   909084 Oct  4  2018 Soup-2.4.gir
  -rw-r--r--   1 root  admin     3535 Oct  4  2018 SoupGNOME-2.4.gir
  -rw-r--r--   1 root  admin   886109 Nov 11 22:23 WebKit2-4.0.gir
  -rw-r--r--   1 root  admin  1358195 Nov 11 22:23 WebKit2WebExtension-4.0.gir
  -rw-r--r--   1 root  admin    23122 Sep 11 22:07 cairo-1.0.gir
  -rw-r--r--   1 root  admin      620 Sep 11 22:07 fontconfig-2.0.gir
  -rw-r--r--   1 root  admin      768 Sep 11 22:07 freetype2-2.0.gir
  -rw-r--r--   1 root  admin    10857 Sep 11 22:07 gir-1.2.rnc
  -rw-r--r--   1 root  admin      938 Sep 11 22:07 libxml2-2.0.gir
  -rw-r--r--   1 root  admin      611 Sep 11 22:07 win32-1.0.gir
  -rw-r--r--   1 root  admin      361 Sep 11 22:07 xfixes-4.0.gir
  -rw-r--r--   1 root  admin      745 Sep 11 22:07 xft-2.0.gir
  -rw-r--r--   1 root  admin     2325 Sep 11 22:07 xlib-2.0.gir
  -rw-r--r--   1 root  admin      808 Sep 11 22:07 xrandr-1.3.gir

I'm also able to compile other programs that use WebKitGTK+. Any help or guidance would be greatly appreciated. Thank you!

jmercouris commented 4 years ago

To future readers, the problem was with the generation of the GIR files which were erroneously putting @rpath, which was then making its way into the typelibs. Full discussion on the issue can be seen here: https://trac.macports.org/ticket/60024#ticket