 |
GTK+ Forums Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
|
|
|
| Author |
Message |
|
|
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 404 Location: Portland, OR USA
|
Posted: Sun Nov 25, 2007 9:21 pm Post subject: GTK+ Libglade Example on Linux and Win32 |
|
|
I finally learned how to build my GTK+ applications in Windows. Although I've got it all working, there are still a few areas I need to learn more about before posting any sort of thorough article or how-to. However, I can share some basic information.
The example project I used consists of two files: main.c and example.glade. They are shown at the bottom of this post or can be downloaded along with the Windows binary (which should work "out of the box" located in example/bin/example.exe): gtk-libglade-win32-example-0.1.zip
Running applications in Windows is easy enough, however, building them from your Linux-style source code and build scripts requires the use of a POSIX environment such as Cygwin or MinGW. I went with the latter so that the deployed application wouldn't require the cygwin DLL.
There are installers for doing much of this, however, I wanted to get a more intimate experience with the process and more up-to-date packages.
The first step to building GTK+ applications in Windows was to install "Automated MinGW Installer" (MinGW-5.1.3.exe) and "MSYS Base System" (MSYS-1.0.10) in that order from http://www.mingw.org/.
Next, I downloaded and installed GTK+ and it's dependency binaries (development and library packages) from http://www.gimp.org/~tml/gimp/win32/downloads.html and libglade binary and development package from http://gladewin32.sourceforge.net/modules/wfdownloads/viewcat.php?cid=10
When all was said and done, I had downloaded and extracted the following to my build environment:
atk-1.20.0.zip
atk-dev-1.20.0.zip
cairo-1.4.10.zip
cairo-dev-1.4.10.zip
gettext-0.14.5.zip
gettext-dev-0.14.5.zip
glib-2.14.2.zip
glib-dev-2.14.2.zip
gtk+-2.12.1.zip
gtk+-dev-2.12.1.zip
jpeg-6b-4-bin.zip
jpeg-6b-4-lib.zip
libglade-2.4.0-bin.zip
libglade-2.4.0-dev.zip
libiconv-1.9.1.bin.woe32.zip
libpng-1.2.8-bin.zip
libpng-1.2.8-lib.zip
libxml2-dev-2.6.27.zip
pango-1.18.3.zip
pango-dev-1.18.3.zip
pkg-config-0.20.zip
tiff-3.8.2-1-bin.zip
tiff-3.8.2-1-lib.zip
zlib123-dll.zip
For some reason, I had to modify zlib's files a bit. I had to copy zlib1.dll to my /bin dir, and I had to rename /lib/zdll.lib to /lib/libz.a
This demo compiles in Windows with:
| Code: (Plaintext) | 1
| cc -Wall -g main.c -o example.exe -mwindows `pkg-config --cflags --libs gtk+-2.0 libglade-2.0` | (Having main.c come before the pkg-config part is important)
And compiles in Linux with:
| Code: (Plaintext) | 1
| cc -Wall -g main.c -o example.exe `pkg-config --cflags --libs gtk+-2.0 libglade-2.0` |
main.c
| Code: (C) | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <gtk/gtk.h>
#include <glade/glade.h>
#define GLADE_FILE "example.glade"
int
main (int argc, char *argv[])
{
GladeXML *gxml;
GtkWidget *window, *platform, *glib_version, *gtk_version;
GtkWidget *user_name, *home_dir;
#ifdef G_OS_WIN32
const gchar *os = "Windows";
#endif
#ifdef G_OS_UNIX
const gchar *os = "Unix";
#endif
gtk_init (&argc, &argv);
gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
window = glade_xml_get_widget (gxml, "window");
platform = glade_xml_get_widget (gxml, "platform");
glib_version = glade_xml_get_widget (gxml, "glib_version");
gtk_version = glade_xml_get_widget (gxml, "gtk_version");
user_name = glade_xml_get_widget (gxml, "user_name");
home_dir = glade_xml_get_widget (gxml, "home_dir");
/* call gtk_main_quit() when the window's "x" is clicked */
glade_xml_signal_connect (gxml, "on_window_destroy",
G_CALLBACK (gtk_main_quit));
glade_xml_signal_connect (gxml, "on_close_button_clicked",
G_CALLBACK (gtk_main_quit));
/* free Glade XML object */
g_object_unref (G_OBJECT (gxml));
gtk_label_set_text (GTK_LABEL (platform), os);
gtk_label_set_text (GTK_LABEL (glib_version), g_strdup_printf ("%d.%d.%d",
glib_major_version,
glib_minor_version,
glib_micro_version));
gtk_label_set_text (GTK_LABEL (gtk_version), g_strdup_printf ("%d.%d.%d",
gtk_major_version,
gtk_minor_version,
gtk_micro_version));
gtk_label_set_text (GTK_LABEL (user_name), g_get_user_name ());
gtk_label_set_text (GTK_LABEL (home_dir), g_get_home_dir ());
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
|
example.glade
| Code: (Plaintext) | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
| <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Sat Nov 24 11:03:44 2007 -->
<glade-interface>
<widget class="GtkWindow" id="window">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">12</property>
<property name="title" translatable="yes">Example</property>
<property name="resizable">False</property>
<signal name="destroy" handler="on_window_destroy"/>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label_xalign">0</property>
<property name="shadow_type">GTK_SHADOW_NONE</property>
<child>
<widget class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="top_padding">8</property>
<property name="left_padding">12</property>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="n_rows">5</property>
<property name="n_columns">2</property>
<property name="column_spacing">5</property>
<property name="row_spacing">5</property>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Platform:</property>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">GLib Version:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">GTK+ Version:</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">User Name:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Home Dir:</property>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="platform">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="glib_version">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="gtk_version">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="user_name">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="home_dir">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes"><b>Cross Platform GTK+ and Libglade</b></property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">1</property>
<property name="xscale">0</property>
<property name="top_padding">12</property>
<child>
<widget class="GtkButton" id="close_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">gtk-close</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_close_button_clicked"/>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface> | [/code]
Last edited by Micah Carrick on Thu Nov 29, 2007 11:14 pm; edited 1 time in total |
|
| Back to top |
|
 |
Ben Familiar Face
Joined: 18 Nov 2007 Posts: 14
|
Posted: Wed Nov 28, 2007 2:09 pm Post subject: Re: GTK+ Libglade Example on Linux and Win32 |
|
|
| Micah Carrick wrote: |
When all was said and done, I had downloaded and extracted the following to my build environment:
atk-1.20.0.zip
....
|
Micah , I am trying to follow your instructions , I downloaded all the packages you put on the list , but I am not sure on what you mean to extract in the build environment. I installeg mgwin and msys , but I
do not udnerstand how to install these packages... just extract all their contents in the c:/mingw/bin ?
thanks
Ben |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 404 Location: Portland, OR USA
|
Posted: Wed Nov 28, 2007 3:10 pm Post subject: |
|
|
The way I did it, was extract them all to C:\MinGW (they zip files have the remaining structure, ie: /bin, /lib, etc). However, I was told on the mailing list that people usually install them into a separate path so that MinGW has only minGW stuff, and their GTK+ development environment is elsewhere. I'm not sure how that all works actually.
So, if you want the way that I have experience, just extract them all to C:\MinGW and let me know any other problems you have. |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 404 Location: Portland, OR USA
|
Posted: Wed Nov 28, 2007 3:13 pm Post subject: |
|
|
Just for a bit of clearification, I was going to blog the details of my installation, however, I know it's not quite right yet.
I had some help from Tor on the gtk-app-devel mailing list. Here's a link to the thread in which I posed some quesions should you be curious:
http://www.nabble.com/forum/ViewPost.jtp?post=13939615&framed=y |
|
| Back to top |
|
 |
Ben Familiar Face
Joined: 18 Nov 2007 Posts: 14
|
Posted: Thu Nov 29, 2007 4:32 pm Post subject: |
|
|
Thank you for the reply.
I tryed to complete the installation as you reccomended. I am not sure if I did it correctly, but I open the msys shell , I moved into the project folder (where are located example.glade and main.c) and I run the compile command you wrote above for windows.
| Code: (Plaintext) | 1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
cc -Wall -g main.c -o example.exe -mwindows `pkg-config --cflags --libs gtk+-2.0 libglade-2.0`
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
Package libglade-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libglade-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libglade-2.0' found
|
I do not understand how to add the PKG_CONFIG_PATH (?) |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 404 Location: Portland, OR USA
|
Posted: Thu Nov 29, 2007 4:36 pm Post subject: |
|
|
Sorry, I forgot to tell you about 1 other step:
In order for pkg-config to work, the path where all the .pc files live must be set. You can do this every time you start a MSYS session by exporting the PKG_CONFIG_PATH, or add this line to c:\devel\msys\1.0\msys.bat:
| Code: (Plaintext) | 1 2
|
set PKG_CONFIG_PATH=/mingw/lib/pkgconfig | |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 404 Location: Portland, OR USA
|
Posted: Thu Nov 29, 2007 4:37 pm Post subject: |
|
|
When that's working, you should be able to output the compiler and linker flags for GTK with something like:
pkg-config --cflags --libs gtk+-2.0
If that works, then pkg-config is able to find the .pc files (which probably live in /mingw/lib/pkgconfig). |
|
| Back to top |
|
 |
Ben Familiar Face
Joined: 18 Nov 2007 Posts: 14
|
Posted: Fri Nov 30, 2007 4:04 pm Post subject: |
|
|
Thank you for your help.
I put the set in the msys.bat and it works , only thing I noticed is that
cc is not recognized as valid command. I have to use gcc , this work
and compiles the file but at the end I have another error..
| Code: (Plaintext) | 1 2 3 4 5 6
|
c:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lz
collect2: ld returned 1 exit status
|
Yesterday I tried to install the same amount of packages and software on antoher laptop i have , there i can compile well the software (using gcc) , I did not experienced the pkgproblem after the installation and I did not put anything in msys.bat . The environmental path was recognized automatically.
Is very nice see your little project running in both Linux and windows :D
I just tryed to take the .exe file i got after compiling and I tryed to open it from another wxp machine which does not has any gtk or glade libraries, when I run the exe file i get an error , on that machine the gui does not appear. Now i am not sure I have to install any kind of runtime environment for the GTK on the machines that are suppose to run the software.. |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 404 Location: Portland, OR USA
|
Posted: Fri Nov 30, 2007 4:14 pm Post subject: |
|
|
Go into the lib dir, and find the zlib library. Rename it to libz.a. So...
| Code: (Plaintext) | 1 2
| cd /mingw/libg
cp zdll.lib libz.a |
I had to do that too, but I thought it was fixed by the list of packages I supplied. Guess not.
Basically, the pkg-config .pc files are specifying -lz as the linker flag for zlib. This means it's looking for a library called "z" so we use the name lib<name>.a |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 404 Location: Portland, OR USA
|
Posted: Fri Nov 30, 2007 4:19 pm Post subject: |
|
|
| Quote: | | Now i am not sure I have to install any kind of runtime environment for the GTK on the machines that are suppose to run the software.. |
The target machine will need the libraries, but not mingw or anything. If you look in the /mingw/bin folder, there are a bunch of windows dll files corresponding to the libraries you downloaded (libgtk.dll, libglib.dll, etc). Your app will need these "at run time" when it is deployed.
One way, is to deploy the target application to C:\Program Files\MyApp\bin\my_app.exe and then all the DLL files live in that bin\ folder as well.
It would also work if the DLL files were copied into C:\Windows\System32\, however, I'm told that is not the way things are done anymore.
You can look at Gaim and Pidgin for windows and where they put the DLL files needed.
This is common for Windows files too. They have all sorts of DLL files they use which typically are installed by their installers or included with Windows if they are common enough. |
|
| Back to top |
|
 |
ZuLuuuuuu Familiar Face
Joined: 20 Dec 2007 Posts: 6
|
Posted: Thu Dec 20, 2007 6:32 pm Post subject: |
|
|
Hi,
I just began GTK programming. I found instructions to compile a GTK application on Linux systems and be able to compile my first Hello World program on a Xubuntu. But I couldn't find any guide to setup a developer environment on a Windows system until your post. I followed what you said in this guide and the replies and am now able to compile my first program also on Windows. Thanks!
By the way, I've sent you an email wihich says that the forum didn't sent me an activation email, well, it sent a little late but sent it :) |
|
| Back to top |
|
 |
ZuLuuuuuu Familiar Face
Joined: 20 Dec 2007 Posts: 6
|
Posted: Thu Dec 20, 2007 8:45 pm Post subject: |
|
|
| I have a question, we mentioned about giving dlls along with our application. Is GTK Runtime Environment enough to execute for example the application on this thread? I mean, can we also ask our user to install GTK Runtime Environment instead of distributing the dlls along with our application? |
|
| Back to top |
|
 |
Micah Carrick Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 404 Location: Portland, OR USA
|
Posted: Thu Dec 20, 2007 9:03 pm Post subject: |
|
|
In theory... yes, however, you app will have to know where those are being installed to. This is where I left off--figuring out that part. To figure that part out, you can...
1. Look at win32 pidgin sources.
2. Look at win32 gimp sources.
3. Ask on the gtk mailing list where there are more Win32 GTK+ developers than are presently visiting this forum. |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group CodeBB 1.0 Beta 2
|