www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - hello world with glib

reply Sonia Hamilton <sonia snowfrog.net> writes:
Hi, I'm trying to get a "hello world" going to call a C function from
[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

% cat hello.d
import std.stdio;
extern(C) GDateTime *g_date_time_new_now (GTimeZone *tz);
void main() {
  writeln("Hello, world");
  GDateTime *gdt;
}

I've got the [2]Interfacing to C page bookmarked :-)

Thanks for any help, Sonia.

References

1. http://developer.gnome.org/glib/2.34/
2. http://dlang.org/interfaceToC.html
Dec 18 2012
parent reply "Mike Parker" <aldacron gmail.com> writes:
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've got the [2]Interfacing to C page bookmarked :-)

 Thanks for any help, Sonia.

 References

 1. http://developer.gnome.org/glib/2.34/
 2. http://dlang.org/interfaceToC.html
You might want to add this series as well, starting with part 1: http://www.gamedev.net/blog/1140/entry-2254003-binding-d-to-c/
Dec 18 2012
parent reply "Mike Parker" <aldacron gmail.com> writes:
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;
Dec 18 2012
next sibling parent Artur Skawina <art.08.09 gmail.com> writes:
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
Dec 18 2012
prev sibling parent Sonia Hamilton <sonia snowfrog.net> writes:
Thanks for all those replies, they really help :)

Sonia.

On Wed, Dec 19, 2012, at 7:05, Artur Skawina wrote:
 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
Dec 19 2012