#How to do a sample GTK application with Zig
1 messages · Page 1 of 1 (latest)
as in for building gtk or just linking against it?
building gtk seems impractical, but linking is as easy as doing
exe.linkLibC()
exe.linkSystemLibrary2("gtk+4", .{})
(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)
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
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
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")));
hm weird
it's saying you didnt link against libc
but you did
make sure youre compiling it with zig build
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
and you are compiling it with zig build right
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
yeah that's wrong
anything you put in build.zig will be ignored unless you use zig build
yeah makes sense
since what I told you to do is only correct on 0.12
but if you installed zig using pacman, youd probably be on 0.11.0
instead of the linkSystemLibrary2 line
do
exe.linkSystemLibraryPkgConfigOnly("gtk+4")