#How to do a sample GTK application with Zig

1 messages · Page 1 of 1 (latest)

safe tinsel
#

Does somebody have sample build script including GTK?

ocean sable
#

(the reason you want to use linkSystemLibrary2 instead of linkSystemLibrary is because the former uses pkg-config, which is necessary for gtk, and the latter does not)

safe tinsel
#

just using it, I'm desperately searching for something that enables me to level up from cli fuckery to GUI

#

and I con't want to use C++ and C

ocean sable
#

so yeah link it like I said above
and then import the headers using

@cImport(@cInlcude("GTK/gtk.h"))

and itll return a struct (just like @import) with the gtk C api

#

now, ive never tried gtk like this before
but it should work just like that
just might not be a very fun experience (though when is gui programming ever)
id recommend using something much simpler like imgui unless you really need a super robust gui

safe tinsel
#

I think I did everything you said

#

just sudo pacman -S gtk4

#

this is the sample in my build.zig:

#
    // Add GTK
    exe.linkLibC();
    exe.linkSystemLibrary2("gtk+4", .{});
#

and in my main.zig (everthing as the sample zig init-exe gave me):

const gtk = @cImport((@cInclude("GTK/gtk.h")));
ocean sable
# safe tinsel

hm weird
it's saying you didnt link against libc
but you did

#

make sure youre compiling it with zig build

safe tinsel
#

got a fresh EndeavourOS build, fresh pacman -S zig, fresh everything, Mason got that zig LS etc., using a bare bones zig init-exe file and adding my shit to it

ocean sable
#

and you are compiling it with zig build right

safe tinsel
#

um I was zig run src/main.zig

#

I'm on KDE Plasma but I installed GTK 4 with sudo pacman -S gtk4

#

yeah build command just exits with error code 1

ocean sable
ocean sable
#

instead of the linkSystemLibrary2 line
do
exe.linkSystemLibraryPkgConfigOnly("gtk+4")