hello world with glib
Artur Skawina
art.08.09 at gmail.com
Tue Dec 18 12:05:15 PST 2012
On 12/18/12 20:23, Mike Parker wrote:
> On Tuesday, 18 December 2012 at 19:21:09 UTC, Mike Parker wrote:
>> On Tuesday, 18 December 2012 at 18:24:03 UTC, Sonia Hamilton wrote:
>>
>>> [1]glib. I'm having problems compiling, what would the correct command
>>> line options?
>>>
>>> % dmd -I/usr/include/glib-2.0 hello.d -L-L/usr/local/lib -L-lglib-2.0
>>> hello.d(3): Error: undefined identifier GDateTime
>>> hello.d(3): Error: undefined identifier GTimeZone
>>
>> Your problem isn't the command line options, but that you're missing definitions of GDateTime and GTimeZone. You'll need to define those somewhere, perhaps the top of your file here for testing, so that D can know what they are.
>
> I just took a look at the GLib docs and see that both of these are opaque structs, so this should do it for you:
>
> struct GDateTime;
> struct GTimeZone;
>
And if you don't want to do all of that manually, you could use
http://repo.or.cz/w/girtod.git
which would make a simple glib D hello-world program look like
import glib = gtk2.glib2;
import std.stdio, std.conv;
void main() {
auto tz = glib.TimeZone.new_local();
scope (exit) tz.unref();
auto dt = glib.DateTime.new_now(tz);
scope (exit) dt.unref();
writeln("Hello World! It is " ~ to!string(dt.format("%c")));
}
Compile with
gdc -fdeprecated -O2 -I $PATH_TO_GIRTOD glibhello.d $PATH_TO_GIRTOD/gtk2/glib2.o `pkg-config --libs glib-2.0`
This might only work with GDC right now; I have no idea about DMD - never tried it.
There are other gtk bindings out there (eg gtkd) that may work with that compiler
and probably support glib too.
artur
More information about the Digitalmars-d-learn
mailing list