GLibSharp: Difference between revisions

From Wiki Maui Linux NET
Jump to navigation Jump to search
Created page with "{{Infobox software | name = GLibSharp | logo = GTK_logo.svg | developer = GNOME Project, Xamarin, and community contributors | released = {{Start date|2002}} | programming_language = C# | operating_system = Cross-platform | platform = .NET, Mono | genre = Utility and core library bindings | license = GNU Lesser General Public License | website = [https://github.com/GtkSharp/GtkSharp GitHub repository] }} '''GLi..."
 
 
Line 78: Line 78:


== See also ==
== See also ==
* [[GLib]]
* [[GtkSharp]]
* [[GtkSharp]]
* [[GioSharp]]
* [[GioSharp]]
Line 85: Line 84:
* [[CairoSharp]]
* [[CairoSharp]]
* [[Mono (software)]]
* [[Mono (software)]]
* [[.NET (software framework)]]


== External links ==
== External links ==

Latest revision as of 13:05, 20 October 2025

GLibSharp
Developer(s) GNOME Project, Xamarin, and community contributors
Initial release

2002

Latest version
Programming language C#
Operating system Cross-platform
Platform .NET, Mono
Type Utility and core library bindings
License GNU Lesser General Public License
Website GitHub repository


GLibSharp is a set of C# bindings for the GLib library, the low-level core utility library of the GNOME platform. It forms the foundation of the GtkSharp ecosystem, providing data structures, event loops, object systems, and utilities used by higher-level libraries such as GioSharp, GdkSharp, and GtkSharp itself.

Overview of GLib

GLib is a fundamental library that underpins much of the GNOME software stack. It provides essential building blocks for application development, including data types, containers, event loops, threads, and the GObject type system that enables object-oriented programming in C.

Key features of GLib include:

  • Core data types (lists, hash tables, arrays, strings, variants)
  • The GObject object and signal system
  • Main event loop and asynchronous task handling
  • Threading, synchronization, and atomic operations
  • Portable file, path, and environment utilities
  • Internationalization and error handling support

Nearly all GNOME and GTK libraries depend on GLib as their base layer.

GLibSharp

GLibSharp provides managed .NET bindings for the GLib library. It enables developers to interact with GLib’s data structures and object system from within C#, while also providing the foundation upon which all other GtkSharp bindings are built.

Using GLibSharp, developers can:

  • Create and use GObjects with C# classes and inheritance
  • Connect and emit signals in an event-driven model
  • Work with GLib data types such as GList, GHashTable, and GVariant
  • Manage main loops and asynchronous callbacks
  • Interoperate with native GLib-based code and libraries

GLibSharp maps the GLib and GObject APIs into idiomatic C# constructs, maintaining compatibility with the underlying type system while exposing familiar managed patterns.

Role in GtkSharp

GLibSharp is the base dependency for all other bindings in the GtkSharp suite:

  • GioSharp – Builds on GLibSharp to provide file, stream, and network services.
  • GdkSharp – Uses GLibSharp for signals and event loops.
  • CairoSharp – Integrates with GLib types for object management.
  • AtkSharp – Relies on GLibSharp for object inheritance and property binding.
  • GtkSharp – The main widget toolkit, which depends on GLibSharp for almost all of its internals.

Without GLibSharp, none of the other GtkSharp components could function, as they all depend on GLib’s type and signal systems.

Version compatibility

GLibSharp has evolved alongside GTK and GLib:

  • **GLibSharp 2.x** – Used with GTK 2 and early Mono environments
  • **GLibSharp 3.x** – Updated for GTK 3 and GLib 2.40+
  • **GLibSharp 4.x** – Planned for GTK 4 and modern .NET 6+ runtimes

Example

A minimal example of using GLibSharp’s main loop:

using GLib;

public class Example
{
    public static void Main()
    {
        MainLoop loop = new MainLoop();
        Timeout.Add(1000, () => { 
            Console.WriteLine("Tick...");
            return true; 
        });
        loop.Run();
    }
}

See also