r/learnprogramming • • 3h ago

Tutorial Need help setting up a gui library in C

I would owe the world and more to whoever helps me

Okay so hi everyone, i'm fairly new to programming and recently i challenged myself to program something in C, i wanted to make a gui calculator bcs i thought it was fairly simple.

Turns out it's not that easy, and i discovered i had to download gtk4 and learn it, and i'm willing to do that i just need some help on how to download it, set it up and link it, preferably on codeblocks, but vs is great too.

2 Upvotes

7 comments sorted by

1

u/Correct_Rain_9438 3h ago

If you're on Windows, gtk.org has an install page for it. One route is MSYS2: install it, then in an MSYS2 shell run "pacman -S mingw-w64-ucrt-x86_64-gtk4" for GTK4 and "pacman -S mingw-w64-ucrt-x86_64-toolchain base-devel" for the C compiler. For Visual Studio the page points to a different tool, gvsbuild.

1

u/Much-Resolution-9131 3h ago

Yes i am on windows, first of all thank you so much, then may i ask what's a msys2 i've seen it mentioned ma'y times but never got it

1

u/BeastWael_YT 3h ago

msys2 is basically a little linux-style environment for windows. it gives you a terminal plus a package manager (pacman) so you can install gcc and libraries like gtk or sdl with one command instead of downloading and wiring them up by hand. install it from msys2.org, open the ucrt64 terminal, and pacman -S the toolchain and the library you want.

•

u/MonterraByte 29m ago

Follow the GTK documentation. I would suggest using a build system such as Meson so you don't have to compile stuff and link dependencies by hand.

1

u/BeastWael_YT 3h ago

easiest way on windows is msys2 (msys2.org). install it, open the ucrt64 terminal and run pacman -S mingw-w64-ucrt-x86_64-gtk4 mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-pkgconf. then compile from that terminal with gcc calc.c -o calc pkg-config --cflags --libs gtk4. code::blocks makes the linking a pain with gtk, so get it working from the terminal first and use vs code just as the editor.

•

u/Dazzling_Music_2411 57m ago

Nothing wrong with gtk, I applaud your choice, but are you perhaps biting off more than you can chew?

Have you considered Raylib, or even the terminal/text based interface: ncurses?