digitalmars.D.learn - hello world with glib
- Sonia Hamilton (18/18) Dec 18 2012 Hi, I'm trying to get a "hello world" going to call a C function from
- Mike Parker (8/20) Dec 18 2012 Your problem isn't the command line options, but that you're
- Mike Parker (5/19) Dec 18 2012 I just took a look at the GLib docs and see that both of these
- Artur Skawina (20/37) Dec 18 2012 And if you don't want to do all of that manually, you could use
- Sonia Hamilton (3/52) Dec 19 2012 Thanks for all those replies, they really help :)
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
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 GTimeZoneYour 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.htmlYou 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
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: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;[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 GTimeZoneYour 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.
Dec 18 2012
On 12/18/12 20:23, Mike Parker wrote:On Tuesday, 18 December 2012 at 19:21:09 UTC, Mike Parker wrote: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. arturOn Tuesday, 18 December 2012 at 18:24:03 UTC, Sonia Hamilton wrote: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;[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 GTimeZoneYour 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.
Dec 18 2012
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: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. arturOn Tuesday, 18 December 2012 at 18:24:03 UTC, Sonia Hamilton wrote: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;[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 GTimeZoneYour 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.
Dec 19 2012