ToshioCP / Gtk4-tutorial

GTK 4 tutorial for beginners
https://toshiocp.github.io/Gtk4-tutorial/
548 stars 50 forks source link

GtkDirectoryList Error building template #10

Closed gavr123456789 closed 3 years ago

gavr123456789 commented 3 years ago

There are Gtk-CRITICAL when run list3.c example.

sh-5.1$ ./a.out 

(a.out:33843): Gtk-CRITICAL **: 03:22:40.840: Error building template for list item: .:0:0: No function named `get_file_name`.

(a.out:33843): Gtk-CRITICAL **: 03:22:40.840: Error building template for list item: .:0:0: No function named `get_file_name`.

(a.out:33843): Gtk-CRITICAL **: 03:22:40.840: Error building template for list item: .:0:0: No function named `get_file_name`.

Compiled with gcc `pkg-config --cflags gtk4` c.c `pkg-config --libs gtk4`

GTK version: 4.2.1-1 Linux: Arch

ToshioCP commented 3 years ago

Gavr, Thank you for posting the issue.

Compile it with -Wl,--export-dynamic option, then the error won't happen.

GtkBuilder builds the template at runtime. It refers to the symbol table to find the function get_file_name. So, the linker needs to add the symbol table to a.out. "-Wl,--export-dynamic! option makes it possible.

$ gcc -Wl,--export-dynamic `pkg-config --cflags gtk4` $1.c `pkg-config --libs gtk4`

There are a shell file comp in the misc directory. You can use it as well.

$ bash comp list3

If you want to use comp as a command:

$ mkdir $HOME/bin
$ cp comp $HOME/bin/comp
$ chmod +x $HOME/bin/comp

After re-login, you can compile it as follows as well.

$ comp list3

The file comp is used in section 24 to compile list3.c.

gavr123456789 commented 3 years ago

Thanks, now it works, its really the best guide for GTK 4 now.
I think there should be a mention of this in section 24.

ToshioCP commented 3 years ago

Thank you for your suggestion. It is helpful to improve this tutorial. I've modified section 24 and put some explanation about -Wl,--export-dynamic option.