FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help: An example dui install for an idiot?

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
hauptmech



Joined: 14 Jan 2007
Posts: 20
Location: Wellington, NZ

PostPosted: Sun Jan 14, 2007 2:04 pm    Post subject: Help: An example dui install for an idiot? Reply with quote

I'm trying to set up D & DUI on linux (zenwalk distro if it matters). As an sporadic and casual user of linux I've learned that the most common reason for my installation failures is an environment variable or softlink that well duh; any idiot (sans me) would add during the course of install.

I tried the duit setup program. It hangs after compiling the GL examples. The examples run fine... It seems to put stuff roughly where I expect but when I try compile duit/demos/gtk/HelloWorld.d it dies while linking. This only ofter adding include paths and library paths to the command line that I'd rather not have to;

So; Would somebody be kind enough to walk me through how they (and I *should* have) installed dmd & then dui? Especially important are config file entries and environment variables that no sane D/duit programmer would be without.

I realize I have left out information you need to help with my specific problem; hopefully the reply is generic enough to help others in my general situation...

Thanks
_________________
-hauptmech
Back to top
View user's profile Send private message
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Sun Jan 14, 2007 3:14 pm    Post subject: Re: Help: An example dui install for an idiot? Reply with quote

hauptmech wrote:
I'm trying to set up D & DUI on linux (zenwalk distro if it matters). As an sporadic and casual user of linux I've learned that the most common reason for my installation failures is an environment variable or softlink that well duh; any idiot (sans me) would add during the course of install.

I tried the duit setup program. It hangs after compiling the GL examples. The examples run fine... It seems to put stuff roughly where I expect but when I try compile duit/demos/gtk/HelloWorld.d it dies while linking. This only ofter adding include paths and library paths to the command line that I'd rather not have to;

So; Would somebody be kind enough to walk me through how they (and I *should* have) installed dmd & then dui? Especially important are config file entries and environment variables that no sane D/duit programmer would be without.

I realize I have left out information you need to help with my specific problem; hopefully the reply is generic enough to help others in my general situation...

Thanks

how did you did it?

Code:
dmd demos/gtk/HelloWorld.d -Idemos/gtk:src -c
 gcc HelloWorld.o -o HelloWorld -m32 -lphobos -lpthread -lm -lduit -ldl -L. -lphobos


works for me, if necessary add the -L with the phobos location.

Ant
Back to top
View user's profile Send private message
hauptmech



Joined: 14 Jan 2007
Posts: 20
Location: Wellington, NZ

PostPosted: Mon Jan 15, 2007 3:03 am    Post subject: Thanks Reply with quote

Code:

th[gtk]$ pwd
/home/th/prog/duit1/demos/gtk
th[gtk]$ dmd HelloWorld.d -I/home/th/prog/duit1/src -c
th[gtk]$ gcc HelloWorld.o -o HelloWorld -m32 -lphobos -lpthread -lm -lduit -ldl -L. -lphobos


That worked for me as well. libdl was missing from my first attempt.

Why did you use gcc explicitly for the linking?


BTW I really appreciate all the work you put into duit. i'm looking forward to using it.

Cheers,
_________________
-hauptmech
Back to top
View user's profile Send private message
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Mon Jan 15, 2007 9:12 am    Post subject: Re: Thanks Reply with quote

hauptmech wrote:

Why did you use gcc explicitly for the linking?


I use leds for all my D development.
that was adapted from the commands leds issues.
I don't even know (or care too much) how to pass the libs on the dmd command

hauptmech wrote:

BTW I really appreciate all the work you put into duit. i'm looking forward to using it.

Cheers,

thank you Smile I'll be here if you get stuck again...

Ant
Back to top
View user's profile Send private message
hauptmech



Joined: 14 Jan 2007
Posts: 20
Location: Wellington, NZ

PostPosted: Wed Jan 17, 2007 12:39 am    Post subject: Stuck again... Reply with quote

I'm trying to build duit/demos/gtk/DrawRect.d and failing.

The linker error message is "undefined reference to '_D9invariant12_d_invariantFC6ObjectZv'

If you are unable to build it as well I am guessing a "-release" flag added to your installer.
_________________
-hauptmech
Back to top
View user's profile Send private message
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Wed Jan 17, 2007 9:35 am    Post subject: Re: Stuck again... Reply with quote

hauptmech wrote:
I'm trying to build duit/demos/gtk/DrawRect.d and failing.

The linker error message is "undefined reference to '_D9invariant12_d_invariantFC6ObjectZv'

If you are unable to build it as well I am guessing a "-release" flag added to your installer.


some demos are too old to build, I should either update or remove them.
I don't remember what is the DrawRect...

Ant
Back to top
View user's profile Send private message
hauptmech



Joined: 14 Jan 2007
Posts: 20
Location: Wellington, NZ

PostPosted: Wed Jan 17, 2007 6:18 pm    Post subject: Re: Stuck again... Reply with quote

Here is what I want to run; It gives the same linker error...
Code:

module gtk.tut1;

private import gtk.AboutDialog;
private import gtk.Widget;
private import gtk.Window;
private import gtk.Label;
private import gtk.Button;
private import gtk.VBox;
private import gtk.Duit;
private import std.stdio;
private import gtk.Image;

private import gdk.gdktypes;
private import gtk.gtktypes;
private import gobject.Signals;
private import gtk.Timeout;

private import gdk.Event;

extern(C) static void onClicked(GtkButton* buttonStruct, Button button)
{
      writefln("\nOn click from Hello World ?s",button);
}

extern(C) static void hello(GtkWidget* widget,gpointer data)
{
    writefln ("Hello World\n");
}


extern(C) static gboolean delete_event(GtkWidget *widget,GdkEvent  *event,gpointer   data )
{
    writefln ("delete event occurred\n");
    return 1;
}

extern(C) static void destroy( GtkWidget *widget, gpointer   data )
{
    Duit.exit(0);
}

void main(char[][] args)
{
   
   Duit.init(args);
   Window window = new Window(GtkWindowType.TOPLEVEL);
   Button button = new Button("Goodbye C++");
   
        Signals.connectData(cast(void*)window.getWindowStruct,"delete_event",cast(GCallback)&delete_event,null,null,cast(ConnectFlags)0);     
    Signals.connectData(cast(void*)window.getWindowStruct,"destroy",cast(GCallback)&destroy,null,null,cast(ConnectFlags)0);     

   window.setBorderWidth = 10;

   Signals.connectData(cast(void*)button.getButtonStruct,"clicked",cast(GCallback)&hello,null,null,cast(ConnectFlags)0);     
   window.add(button);
   
   button.show();
   window.show();
   Duit.main();
   
    return 0;
}



My attempt to build;
Code:

th[gtk]$ dmd gtktut1.d -release -c
th[gtk]$ gcc gtktut1.o -o tut -lm -ldl -lphobos -lduit -lpthread


and the error;
Code:


th[gtk]$ gcc gtktut1.o -o tut -lm -ldl -lphobos -lduit -lpthread
/usr/lib/gcc/i486-slackware-linux/3.4.6/../../../libduit.a(Widget.o)(.gnu.linkonce.t_D3gtk6Widget6Widget15getWidgetStructMFZPS3gtk8gtktypes9GtkWidget+0xa): In function `_D3gtk6Widget6Widget15getWidgetStructMFZPS3gtk8gtktypes9GtkWidget':
: undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
/usr/lib/gcc/i486-slackware-linux/3.4.6/../../../libduit.a(Widget.o)(.gnu.linkonce.t_D3gtk6Widget6Widget8getWidthMFZi+0xa): In function `_D3gtk6Widget6Widget8getWidthMFZi':
: undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
/usr/lib/gcc/i486-slackware-linux/3.4.6/../../../libduit.a(Widget.o)(.gnu.linkonce.t_D3gtk6Widget6Widget9getHeightMFZi+0xa): In function `_D3gtk6Widget6Widget9getHeightMFZi':
: undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
/usr/lib/gcc/i486-slackware-linux/3.4.6/../../../libduit.a(Widget.o)(.gnu.linkonce.t_D3gtk6Widget6Widget11getDrawableMFZC3gdk8Drawable8Drawable+0xb): In function `_D3gtk6Widget6Widget11getDrawableMFZC3gdk8Drawable8Drawable':
: undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
/usr/lib/gcc/i486-slackware-linux/3.4.6/../../../libduit.a(Widget.o)(.gnu.linkonce.t_D3gtk6Widget6Widget9setCursorMFC3gdk6Cursor6CursorZv+0xb): In function `_D3gtk6Widget6Widget9setCursorMFC3gdk6Cursor6CursorZv':
: undefined reference to `_D9invariant12_d_invariantFC6ObjectZv'
/usr/lib/gcc/i486-slackware-linux/3.4.6/../../../libduit.a(Widget.o)(.gnu.linkonce.t_D3gtk6Widget6Widget11resetCursorMFZv+0xa): more undefined references to `_D9invariant12_d_invariantFC6ObjectZv' follow
collect2: ld returned 1 exit status


ideas?
_________________
-hauptmech
Back to top
View user's profile Send private message
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Thu Jan 18, 2007 1:03 am    Post subject: Re: Stuck again... Reply with quote

hauptmech wrote:
Here is what I want to run; It gives the same linker error...
Code:

...



yaikes! looks like Gtk, avoid!

here is my suggestion:
Code:

module gtk.tut1;

private import gtk.Duit;
private import gtk.MainWindow;
private import gtk.Button;

private import std.stdio;

void main(char[][] args)
{

   // Duit callbacks are delegates, not functions
   // so you cannot use a top level function as a call back
   // usually you'll have a method on a class
   void onClicked(Button button)
   {
      writefln("\nOn click from Hello World ?s",button);
   }
   
   // of course you can add all sort of event callbacks to all widgets.
   // use the addOnXxxxxx methods
   void enterOnButton(Button button)
   {
      writefln("\nThe mouse just entered on the button!");
   }
   
   void leftTheButton(Button button)
   {
      writefln("\noh! no, the mouse is gone...");
   }
   
   Duit.init(args);
   // you can have as many MainWindow as you want
   // but the default behaviour is to exit the application
   // when the last one is closed
   // so: no delete or destroy event.
   // to have more control on the delete event subclass the main window
   // and override the windowDelete method
   // when necessary to connect to signal use the addOnXxxxx methods
   MainWindow window = new MainWindow("Goodbye C++");

   Button button = new Button("Goodbye Gtk", &onClicked);
   button.addOnEnter(&enterOnButton);
   button.addOnLeave(&leftTheButton);
   
   window.setBorderWidth = 10;
   window.add(button);
   
   window.showAll();

   Duit.main();
   
   return 0;
}



and to compile it:
Code:
dmd tut1.d -release -c -I../Duit/trunk/src
gcc tut1.o -o tut -lm -ldl -lduit -lpthread -L../Duit/trunk -lphobos


I added the import for Duit to the dmd command, I don't know if you need that
(looks like you don't from your report)
I moved the -lphobos to the end - that's a documented thing on the linker
I don't have time for those things, sometimes I just keep adding multiple entries for the libs until the linker doesn't complain anymore. Usualy just reordering the libs is enough.

Now, the big change was on the code itself.
Move away from the Gtk style to a Duit style. Gtk is very uggly.
Looking at the Gtk application code you can see that Gtk was not designed to be used directly - well, yes it was but I choose not to believe that.
Gtk is very good for bindings from other languages and that's an important parte of the Gtk project.

Duit seems cleaner and easier to use.
You can still use the vanilla gtk from Duit but for that you don't need Duit.

On the callbacks:
for instance, Button has 6 addOnXxxxxx methods to add callbacks to actions on the button
plus all the addOnXxxxxxxxxx on the super classes...
In this case I added the clicked signal on the constructor as it's very common
to be interested on the clicked event on the buttons.
Don't use the the Signals.connect... I spend days trying to simplify that.
I hope you agree the Duit way is better for the application code...

All this is my fault, there is no proper documentation...
check if the code for DuitTests helps...

Last note, try using leds for your D development
(there are other IDEs available but leds is the one I created and use)
check http://leds.sf.net
It's not up-to-date but will give you an idea of it.
grab leds and the scintilla lib from
http://www.dsource.org/projects/leds/browser/downloads

Ant
Back to top
View user's profile Send private message
hauptmech



Joined: 14 Jan 2007
Posts: 20
Location: Wellington, NZ

PostPosted: Thu Jan 18, 2007 3:31 am    Post subject: Re: Stuck again... Reply with quote

Quote:

<snip>
All this is my fault, there is no proper documentation...
check if the code for DuitTests helps...

Last note, try using leds for your D development
(there are other IDEs available but leds is the one I created and use)
check http://leds.sf.net
It's not up-to-date but will give you an idea of it.
grab leds and the scintilla lib from
http://www.dsource.org/projects/leds/browser/downloads

Ant


Great! Shifting the location of -lphobos in the linker command fixed my linking problem. The code example you just gave me is perfect. I also rewrote the code in what I guessed was the OOP way. I have another question regarding it that I will post later.

I'd be happy to do some documentation work. I tried to edit the wiki but couldn't figure out where to log in or register... Do you have to grant a login?

Is there an automated way to document the class structure & members? (Right now I just load all the src files into my editor.)

As far as learning from example: DuitTests is good. I've even been scanning the gui duit installer code. However there is a difference between seeing one working example and learning from the experience of lots of bad ones; of which I plan to write many.

Cheers,



[/quote]
_________________
-hauptmech
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group