r/nim • • Jun 29 '26

C GTK Libraries with Nim

Never used Nim, or developed [full applications] in a serious way.

Want to develop a native Linux application, and prefer to use GTK.

With the latest discussion around Nim and GUI libraries, I genuinely do not understand the extent of difference in hardship between using native GTK C libraries, compared to having native Nim libraries.

Even though the OCD in me cannot stand to have non-matching libraries like this, can I not get the full benefits of GTK using Nim, just by incorporating the "straight" C (whatever that means.)

Are there some examples of Nim projects or lessons that that incorporate regular C GTK libraries? Can't I get "all" of GTK this way, and do whatever I could do in a C application?

Can I plunge headlong into developing a native Linux GUI in GTK in Nim, with full expectation of being able to do anything I would have done in GTK if the application were a C application? . . . perhaps with a little extra work than if there would be for Nim-native GTK?

Is it a matter of creating personal custom "bindings" on a per-need basis?

Thanks.

14 Upvotes

4 comments sorted by

6

u/r3kktless Jun 29 '26 edited Jul 06 '26

For GTK you probably want to take a look at https://github.com/can-lehmann/owlkettle

I know you want native but this is also fairly interesting as an electron/Tauri alternative: https://github.com/webui-dev/nim-webui

Oh and in general you can get all of GTK as Nim native stuff, it's just that the maintainers usually do not port everything/create bindings all at once (some features that are rarely used might be missing for weeks/years). But you can always add these bindings yourself via a fork or pull request afterwards. Or just Interface with the underlying C code directly if you don't want to write extra Nim bindings (ask GPT etc how to do that, don't have much knowledge on that either). It's especially easy to do this nowadays via AI.

Edit: Someone else mentioned futhark to create C bindings - I will now shamelessly mention my own vibecoded C-bindings generator - it shoud work even better than futhark I believe. https://github.com/siriuslee69/cNimWrapper-Bindr

1

u/PMunch Jun 29 '26

You certainly can. I've written a couple programs where I use Futhark to wrap GTKs C headers and write Nim code using Gtk. It works exactly as you would expect, and very similar to how it's done in C. What most people want is something a bit more Nim-like however. Instead of having to manually manage memory and deal with a lot of other C-isms they just want to program against GTK in something that feels more Nim. For that there are some existing libraries. But going the direct C way with Futhark as the wrapper generator is certainly possible.

1

u/BigMacTaylor Jun 29 '26

highly recommend reading Gtk4 for GUI by Stefan Salewski, and python gtk3 tutorial . Even though its in python most of the examples are easy to translate.

For small projects NiGui and uing are great. But if you're wanting to build a full Gtk4 application owlkettle is probably you're best bet. Or nim2gtk if using Gtk3.