Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS cannot find libadwaita #167

Closed
mrunion opened this issue Jul 22, 2024 · 5 comments
Closed

MacOS cannot find libadwaita #167

mrunion opened this issue Jul 22, 2024 · 5 comments

Comments

@mrunion
Copy link
Contributor

mrunion commented Jul 22, 2024

I am trying a simple window and trying to use Adwaita. The error I get when running "nim c..." is:

ld: library 'adwaita-1' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have GTK4 and libAdwaita installed via brew. The code for the app is simple:

import owlkettle
import owlkettle/adw

viewable App:
    text: string

method view(app: AppState): Widget =
    result = gui:
        Window:
            title = "Simple Window"

adw.brew(gui(App()))

If I use GTK4 itself by removing the "adw.brew..." and just using "brew...", and removing the adw import the code runs fine.

pkg-build shows the following output when running "pkg-config --libs libadwaita-1"

-L/opt/homebrew/Cellar/libadwaita/1.5.2/lib -L/opt/homebrew/Cellar/gtk4/4.14.4/lib 
-L/opt/homebrew/Cellar/pango/1.54.0/lib -L/opt/homebrew/Cellar/harfbuzz/9.0.0/lib 
-L/opt/homebrew/Cellar/gdk-pixbuf/2.42.12/lib -L/opt/homebrew/Cellar/cairo/1.18.0/lib 
-L/opt/homebrew/Cellar/graphene/1.10.8/lib -L/opt/homebrew/Cellar/glib/2.80.4/lib 
-L/opt/homebrew/opt/gettext/lib 
-ladwaita-1 -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 
-lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl

Am I doing something wrong or is MacOS not supporting Adwaita, or any other clues?

Thanks in advance!

@can-lehmann
Copy link
Owner

It seems like the shared library file is missing. From the pkg-config output I would assume that it is supposed to be in /opt/homebrew/Cellar/libadwaita/1.5.2/lib. Does this folder contain the shared library? Can you compile & link libadwaita applications written in C using gcc?

@mrunion
Copy link
Contributor Author

mrunion commented Jul 23, 2024

The dynlib is in that location, so I am assuming this is correct? (I am on Apple Silicon, so not sure if that's relevant or not here.)

Contents of /opt/homebrew/Cellar/libadwaita/1.5.2/lib

drwxr-xr-x   6 <.....>  <...>      192 Jul 23 09:47 .
drwxr-xr-x  13 <.....>  <...>      416 Jul 23 09:47 ..
drwxr-xr-x   3 <.....>  <...>       96 Jun 28 12:14 girepository-1.0
-r--r--r--   1 <.....>  <...>  1871184 Jul 23 09:47 libadwaita-1.0.dylib
lrwxr-xr-x   1 <.....>  <...>       20 Jun 28 12:14 libadwaita-1.dylib -> libadwaita-1.0.dylib
drwxr-xr-x   3 <.....>  <...>       96 Jul 23 09:47 pkgconfig

I have not tried using gcc to link anything as this is my first foray into GTK.

@mrunion
Copy link
Contributor Author

mrunion commented Jul 24, 2024

Alright, I tested with a sample Adwaita program (below) in plain C. The program compiled and ran fine with the following compile command:

gcc $(pkg-config --cflags libadwaita-1) -o libadwaitatest-0 libadwaitatest-0.c $(pkg-config --libs libadwaita-1)

However, the nim compiler uses clang. On MacOS, gcc is kind of a "wrapper" for clang so I don't think this is the issue, but I thought I'd bring it up.

Here is the test program I compiled and ran (libadwaitatest-0.c):

#include <adwaita.h>

static void
activate_cb (GtkApplication *app)
{
  GtkWidget *window = gtk_application_window_new (app);
  GtkWidget *label = gtk_label_new ("Hello World");

  gtk_window_set_title (GTK_WINDOW (window), "Hello");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  gtk_window_set_child (GTK_WINDOW (window), label);
  gtk_window_present (GTK_WINDOW (window));
}

int
main (int   argc,
      char *argv[])
{
  g_autoptr (AdwApplication) app = NULL;

  app = adw_application_new ("org.example.Hello", G_APPLICATION_FLAGS_NONE);

  g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);

  return g_application_run (G_APPLICATION (app), argc, argv);
}

@mrunion
Copy link
Contributor Author

mrunion commented Jul 24, 2024

UPDATE: I was wrong -- I changed that line myself and the same error about not finding the adwaita library and it is now looking for libadwaita-1 that is still not found.

---- I was wrong below here ----
I think I may have found the issue.

Notice that it says it cannot find the library "adwaita-1"? png-config can't either:

pkg-config --libs adwaita-1

returns:

Package adwaita-1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `adwaita-1.pc'
to the PKG_CONFIG_PATH environment variable
No package 'adwaita-1' found

The package on MacOS is libadwaita-1, and as above, pkg-config --libs libadwaita-1 returns the library info.

Could it be line 31 in the /owlkettle/bindings/adw.nim using {.passl: "-ladwaita-1".} instead of {.passl: "-llibadwaita-1".}?

@mrunion
Copy link
Contributor Author

mrunion commented Jul 24, 2024

UPDATE: I created a PR #168 to fix this issue. Hopefully this is the correct way.

OR the existing code will compile by adding:

nim c --clibdir:/opt/homebrew/Cellar/libadwaita/1.5.2/lib <myadwaitauicode>.nim

OK, I found the problem! But I don't know the fix.

The issue is that the libadwaita library path is NOT included in the list of library paths when compiling. Here is a snippet that shows the library paths from the compilation using nim and Adwaita:

-L/opt/homebrew/Cellar/gtk4/4.14.4/lib 
-L/opt/homebrew/Cellar/pango/1.54.0/lib 
-L/opt/homebrew/Cellar/harfbuzz/9.0.0/lib 
-L/opt/homebrew/Cellar/gdk-pixbuf/2.42.12/lib 
-L/opt/homebrew/Cellar/cairo/1.18.0/lib 
-L/opt/homebrew/Cellar/graphene/1.10.8/lib 
-L/opt/homebrew/Cellar/glib/2.80.4/lib 
-L/opt/homebrew/opt/gettext/lib 
-lgtk-4 
-lpangocairo-1.0 
-lpango-1.0 
-lharfbuzz 
-lgdk_pixbuf-2.0 
-lcairo-gobject 
-lcairo 
-lgraphene-1.0 
-lgio-2.0 
-lgobject-2.0 
-lglib-2.0 
-lintl 
-L/opt/homebrew/Cellar/cairo/1.18.0/lib 
-lcairo 
-llibadwaita-1   
-ldl

Notice that "-llibadwaita-1" is in the list of libraries, but the path is not.

Adding the following will result in a successful compilation:

-L/opt/homebrew/Cellar/libadwaita/1.5.2/lib

What I don't know is why nim isn't adding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants