GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Jul 25, 2014 5:16 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: GTK installation in visual c++ and windows
PostPosted: Wed May 30, 2007 1:32 am 
Offline
Familiar Face

Joined: Fri May 25, 2007 8:36 am
Posts: 13
Location: Iran
What should I do and what shall I download in order to use gtk in windows xp
I use from visual c++ 2005 . what should I do if I want to introduce gtk to it?
I hope that my good friends will help me in this case as other cases.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 5:16 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
I don't know how up-to-date it is, but, this article discusses it a bit: http://www.yolinux.com/TUTORIALS/GTK+ProgrammingTips.html

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 5:48 am 
Offline
Familiar Face

Joined: Sun Nov 05, 2006 8:56 am
Posts: 19
That site looks pretty good, I usually just install gtk+ dev for win32 and make sure visual studio can find the files.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 5:53 am 
Offline
Familiar Face

Joined: Sun Nov 05, 2006 8:56 am
Posts: 19
Ok here is a quick setup guide:

Download the dev runtime: http://sourceforge.net/project/showfiles.php?group_id=98754&package_id=111411

create a new text file called gtk+_debug.vsprops:
Code:
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioPropertySheet
   ProjectType="Visual C++"
   Version="8.00"
   Name="gtk+ debug"
   >
   <Tool
      Name="VCCLCompilerTool"
      Optimization="0"
      AdditionalIncludeDirectories="$(INCLUDE)"
      RuntimeLibrary="3"
      StructMemberAlignment="4"
      AssemblerOutput="0"
      DebugInformationFormat="4"
   />
   <Tool
      Name="VCLinkerTool"
      AdditionalDependencies="art_lgpl_2.lib asprintf.lib atk-1.0.lib bz2.lib cairo.lib charset.lib croco-0.6.lib fontconfig.lib freetype.lib gdk_pixbuf-2.0.lib gdkglext-win32-1.0.lib gdk-win32-2.0.lib glade-2.0.lib glib-2.0.lib gmodule-2.0.lib gobject-2.0.lib gsf-1.lib gsf-win32-1.lib gthread-2.0.lib gtkglext-win32-1.0.lib gtk-win32-2.0.lib iconv.lib intl.lib jpeg.lib pango-1.0.lib pangocairo-1.0.lib pangoft2-1.0.lib pangowin32-1.0.lib png.lib popt.lib rsvg-2.lib tiff.lib xml2.lib z.lib"
      AdditionalLibraryDirectories="$(LIB)"
      GenerateDebugInformation="true"
      AssemblyDebug="1"
      GenerateMapFile="false"
      SubSystem="1"
      OptimizeForWindows98="1"
   />
</VisualStudioPropertySheet>


and another called gtk+_release.vsprops:
Code:
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioPropertySheet
   ProjectType="Visual C++"
   Version="8.00"
   Name="gtk+ release"
   >
   <Tool
      Name="VCCLCompilerTool"
      Optimization="2"
      FavorSizeOrSpeed="1"
      AdditionalIncludeDirectories="$(INCLUDE)"
      RuntimeLibrary="2"
      StructMemberAlignment="4"
      AssemblerOutput="0"
   />
   <Tool
      Name="VCLinkerTool"
      AdditionalDependencies="art_lgpl_2.lib asprintf.lib atk-1.0.lib bz2.lib cairo.lib charset.lib croco-0.6.lib fontconfig.lib freetype.lib gdk_pixbuf-2.0.lib gdkglext-win32-1.0.lib gdk-win32-2.0.lib glade-2.0.lib glib-2.0.lib gmodule-2.0.lib gobject-2.0.lib gsf-1.lib gsf-win32-1.lib gthread-2.0.lib gtkglext-win32-1.0.lib gtk-win32-2.0.lib iconv.lib intl.lib jpeg.lib pango-1.0.lib pangocairo-1.0.lib pangoft2-1.0.lib pangowin32-1.0.lib png.lib popt.lib rsvg-2.lib tiff.lib xml2.lib z.lib"
      AdditionalLibraryDirectories="$(LIB)"
      GenerateDebugInformation="false"
      AssemblyDebug="0"
      GenerateMapFile="false"
      SubSystem="2"
      OptimizeForWindows98="1"
   />
</VisualStudioPropertySheet>


Include both of these in your project (View -> Other Windows -> Property Manager), if vs still can't find gtk+ then add $(INCLUDE) and $(LIB) under the correct locations in Tools -> Options -> Projects and Solutions -> VC++ Directories


I made it so debug makes main the entry point and generates a console window also. Release needs to have a WinMain entry point like the following:
Code:
/* Windows Specific Code */
#ifdef G_OS_WIN32
#include <windows.h>
int WINAPI WinMain(     
   HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPSTR lpCmdLine,
   int nCmdShow
)
{
   return main (__argc, __argv);
}
#endif


If anybody tries this, let me know how it goes.

A quick tip: I personally think Lucida Console at Font Size 12 looks a lot better (ClearType enabled anyways).





CHANGES
06-19-07: added DebugInformationFormat="4" to debug sheet. Debugging works correctly now


Last edited by xaos5 on Tue Jun 19, 2007 4:41 am, edited 4 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 6:08 am 
Offline
Familiar Face

Joined: Sun Nov 05, 2006 8:56 am
Posts: 19
Here is a simple gtk application to test with:
Code:
#include <gtk/gtk.h>

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

static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{
    g_print ("delete event occurred\n");

    return FALSE;
}

static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    GtkWidget *button;
   
    gtk_init (&argc, &argv);
   
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   
    g_signal_connect (G_OBJECT (window), "delete_event",
            G_CALLBACK (delete_event), NULL);
   
    g_signal_connect (G_OBJECT (window), "destroy",
            G_CALLBACK (destroy), NULL);
   
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
   
    button = gtk_button_new_with_label ("Hello World");
   
    g_signal_connect (G_OBJECT (button), "clicked",
            G_CALLBACK (hello), NULL);
   
    gtk_container_add (GTK_CONTAINER (window), button);
   
    gtk_widget_show (button);
   
    gtk_widget_show (window);
   
    gtk_main ();
   
    return 0;
}

/* Windows Specific Code */
#ifdef G_OS_WIN32
#include <windows.h>
int WINAPI WinMain(     
   HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPSTR lpCmdLine,
   int nCmdShow
)
{
   return main (__argc, __argv);
}
#endif


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 08, 2009 3:49 pm 
Offline

Joined: Tue Sep 08, 2009 3:23 pm
Posts: 4
I've been trying figure out how to get Gtk+ 2.0 to work inside of Visual Studio, so first, thanks for the helpful instructions. They are few and far between, and so far, your instructions are the most understandable and useable.

You did ask for feedback if anyone tried to follow your instructions. The first error I get is (I believe) the same as the warning. "fatal error C1083: Cannot open include file: 'gtk/gtk.h': No such file or directory". And the warning is "The following environment variables were not found: $(INCLUDE)" (This, after I added the reference in the include directory.)

So, now the question is, to what do I define the INCLUDE environment variable? (For those reading this that don't already know, you set an environment variable by running sysdm.cpl -- hit Windows+r to get the Run window. On the Advanced Tab, you'll find the Environment Variables button at the bottom of the dialog.)

So, I took guess or two, and set INCLUDE to the include directory of the GTK Dev installation's include directory. In my case, I unzipped these files in Gtk+ folder on my C-drive, so this becomes "C:\Gtk+\include\gtk-2.0". Of course, I close and reopen the visual studio project so I can get the new environment variable definition.

The first thing that surprises me (but only slightly, because I know this error is going to show eventually), is that it hasn't yet complained because $(LIB) environment variable is not yet defined. But, from here, I get the error that it cannot open include file: 'gio/gio.h'.

So far, as mentioned in this post, I've only downloaded/unzipped the gtk development files. That said, I can't find gio.h anywhere. I'm going to go a hunting, and I'll post back again whatever I find.


Top
 Profile  
 
 Post subject: Followup with Include defined
PostPosted: Tue Sep 08, 2009 6:07 pm 
Offline

Joined: Tue Sep 08, 2009 3:23 pm
Posts: 4
Well, I knew $(LIB) would pop up somewhere.

I don't know if the information here was dated and changes in Gtk+ have made more than just the Gtk dll to be required, or if there was an assumption made that the readers would all just know what files were required, but I didn't have a gio.h file. Rather than track down each of these in turn, I decided to grab the win32 bundle available from the Gtk+ home page (which I'm apparently prevented from posting here?).

After some experimentation (and a little knowledge of Gtk in linux), and I figured out that the INCLUDE variable is defined according to the output of "pkg-config --cflags gtk+-2.0" run from a command prompt after you add the bin folder to your path. So far, I've skipped the -mms-bitflags option set in the output. For those reading this that don't know, pkg-config is a tool used by Gtk+ to determine where all of the dependency libraries and include files are located. This utility is used to build the gcc compiler version. Since this is for VS compiler, I'm not sure how that fits in, so I'll probably have to do another post on that.

In the mean time, now that the libraries are all defined, I make it all the way to the linker, and now it's complaining about missing libraries. So, using what I've figured out so far, I'll have to defined LIB environment variable according to what comes out of pkg-config --libs gtk+-2.0.[/url]


Top
 Profile  
 
 Post subject: Ok, I'm dead here.
PostPosted: Tue Sep 08, 2009 6:15 pm 
Offline

Joined: Tue Sep 08, 2009 3:23 pm
Posts: 4
Well, Visual Studio 2005 is now complaining that it can not find art_lgpl_2.lib. I don't have that file in spite of installing everything I'm supposed to need in the bundled zip file. I'll try to google this library, but I'm not expecting to get this resolved following the instructions on here. So, if you're reading this, hoping to figure out step-by-step instructions on setting up Gtk+ for use in Visual Studio, I'm sorry, but you need to keep looking. This appears to be a dead end.


Top
 Profile  
 
 Post subject: Got the sample code to run
PostPosted: Wed Sep 09, 2009 12:40 pm 
Offline

Joined: Tue Sep 08, 2009 3:23 pm
Posts: 4
Ok, here's what I had to do to make this compile and work under Visual Studio 2005. I'm rather sure this process, with minor changes, will extend to Visual Studio 2008 and likely 2010.

First, you'll need to download and extract the development files for Gtk+. There's a nice little bundle of everything you need, and you can expand it to wherever you like, just remember where it is. When you extract all the files, you'll want to keep the basic directory structure. The bin directory is where pkg-config is located, and just like in the instructions, you'll want to know that pkg-config --cflags gtk+-2.0 works on the command line. For that to happen, you'll need the bin directory defined in your Path.

Next are the include and lib directorys, which you'll have to tell Visual Studio how to find. Under Tools->Options, you can click the tree node for Projects and Solutions, and you'll see VC++ Directories. Selecting that, you'll be offered a drop-down list in the upper right for what function or aspect you want to define the directories. Select Include Files, first, and here's where you'll have to use some grey-matter (your brains). Right now, I've defined gtk-2.0\include, glib-2.0\include, pango-1.0, libpng12, gtk-2.0, glib-2.0, gail-1.0, cairo, and atk-1.0 directories.

However, Gtk has been undergoing some (welcome) changes lately, and this could change. What I did to get this list was I built the code. The compiler will complain about some missing piece, and you'll have to track it down and add it's directory to the list. Boring, but easy enough. The libraries are a little more difficult.

Once you get all of the include directories added, you'll start seeing some LNK errors (from the linker in Visual Studio). First, you'll need to go back to Projects and Solutions->VC++ Directories, and select directories for Library files. In there, add the directory to your lib folder, and recompile. Visual Studio now knows where the libraries are, but not which libraries.

The safe bet here would be to add everything and let the linker sort them out. But, if you have some experience with Gtk and its libraries, you should be able to make some educated guesses about what you need and what you don't. Regardless, the list of Additional Dependencies can be found by selecting the main solution in the Solution Explorer window, and then clicking Project->Properties. Again, you'll see the tree view and you're looking to click on the Linker node. Select Input and Additional Dependencies will be the very first item. Just click and start typing the list of lib files to include in the build. For this example code, only four were required: gtk-win32-2.0.lig, gdk-win32-2.0.lib, glib-2.0.lib, and gobject-2.0.lib.

Hope this helps someone else.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group