Get started with GTK+ using MinGW

02Jun08

If you want to start developing GTK+ applications with MinGW, but don’t know where to begin, here’s a simple tutorial.

  1. Get MinGW and MSYS. Install MinGW first, followed by MSYS.
  2. When MSYS asks about continuing post-install, say yes. When it asks for MinGW, say yes, and provide the install directory.
  3. Get the GTK+ bundle. Extract it into your MinGW install directory.
  4. Get the tutorial files and extract them into your development directory. (1) (2)
  5. Launch MSYS, cd over to your development directory.
  6. Type “make” and press Enter.
  7. Presto! Launch the file either in MSYS (by typing “hello”) or in Windows Explorer.

Notes: (1) The -mwindows flag hides the console window. The console window will never show when the app is launched from MSYS, so always launch from Explorer if you’re planning on releasing your work. (2) The makefile is already set up for multiple sources, so all you have to do is add .c files, separated by spaces to the SRC directive, and the rest will take care of itself. Enjoy!

Advertisements


15 Responses to “Get started with GTK+ using MinGW”

  1. 1 Kristofer

    Hi!

    I followed youre example and downloaded the bundle, unpacked it to the MinGW folder, downloaded and tried to compile the source file. But MinGW complained, “gtk/gtk.h: No such file or directory”. And when I looked in the include folder, there wasn’t any fiolder gtk, but a folder gtk-2.0/gtk. No wonder it couldn’t be found! Isn’t there any way to use pkgconfig to tell the compiler to look in more include folers? I need to add MinGW/include/gtk-2.0 as an include folder to look in, and I don’t know if it’s the only one…

  2. 2 modulatum

    Hi Kristofer, thanks for your comment! I uninstalled my MinGW/MSYS distribution and performed a clean install, and sure enough, I had the same problem. It’s caused by a pair of illegal characters in the pkg-config flags. The new archive is uploaded with this fix in the Makefile. Thanks for pointing out the error!

  3. 3 Kristofer

    Thank you very much!

  4. It has been several years since i setup GTK, and I recall it took some time.
    I followed the directions at the top of the page, and i got the following results
    $ make
    gcc hello.c `pkg-config –cflags –libs gtk+-2.0` -mwindows -c #Create .o
    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
    hello.c:1:21: gtk/gtk.h: No such file or directory
    hello.c:2: error: syntax error before ‘*’ token
    hello.c: In function `main’:
    hello.c:7: error: `GtkWidget’ undeclared (first use in this function)
    hello.c:7: error: (Each undeclared identifier is reported only once
    hello.c:7: error: for each function it appears in.)
    hello.c:7: error: `window’ undeclared (first use in this function)
    hello.c:9: error: `GTK_WINDOW_TOPLEVEL’ undeclared (first use in this function)
    hello.c:11: error: `NULL’ undeclared (first use in this function)
    hello.c:15:2: warning: no newline at end of file
    make: *** [hello.o] Error 1

    I didn’t find any setup instructions with the web page.

    the last time i made a lot of links to get it working.
    any words of wisdom?
    Thanks for any help,
    Tom

  5. 5 modulatum

    @Tom Burrell: I got the same error when I didn’t extract the GTK bundle properly. You’ll have to reinstall MinGW/MSYS and extract GTK again. The process should be very straightforward.

  6. 6 help_pls

    Hello,
    I followed the above steps but i’ve a problem linking the files. These are error when executing the make:

    “$ make
    gcc hello.c `pkg-config –cflags –libs gtk+-2.0` -mwindows -c #Create .o
    hello.c:15:2: warning: no newline at end of file
    gcc.exe: -lgtk-win32-2.0: linker input file unused because linking not done
    gcc.exe: -lgdk-win32-2.0: linker input file unused because linking not done
    gcc.exe: -latk-1.0: linker input file unused because linking not done
    gcc.exe: -lgio-2.0: linker input file unused because linking not done
    gcc.exe: -lgdk_pixbuf-2.0: linker input file unused because linking not done
    gcc.exe: -lpangowin32-1.0: linker input file unused because linking not done
    gcc.exe: -lgdi32: linker input file unused because linking not done
    gcc.exe: -lpangocairo-1.0: linker input file unused because linking not done
    gcc.exe: -lpango-1.0: linker input file unused because linking not done
    gcc.exe: -lcairo: linker input file unused because linking not done
    gcc.exe: -lgobject-2.0: linker input file unused because linking not done
    gcc.exe: -lgmodule-2.0: linker input file unused because linking not done
    gcc.exe: -lglib-2.0: linker input file unused because linking not done
    gcc.exe: -lintl: linker input file unused because linking not done
    gcc hello.o `pkg-config –cflags –libs gtk+-2.0` -mwindows -o hello.exe #Link .o
    rm hello.o #Remove .o”

    It creates an executable but it doesn’t work, if I run it from msys console a window appears(tittled hello world!), but nothing inside of it. If i run it from windows an error appears complaining about libglib-2.0.0.dll, your help will be really appreciated 🙂

  7. 7 modulatum

    @help_pls: I suspect your problem is in not extracting the GTK bundle properly, hence all the “input file unused” messages and the missing .dlls. Try the process again, making sure the bundle extracts to your MinGW folder.

  8. 8 Thanks

    Thanks a lot. This has helped me out a great deal. I was messing with it earlier before coming to this site. I guess the problem was that the GTK files were not extracting properly into the MinGW directory.

  9. Hi
    Thanks for this interesting gtk+ info.
    I followed instructions and got some output but also a load of errors/warnings.
    I get the hello.exe which is just a simple windows frame/window app which runs from MYSYS or from the development folder.
    I will play around with this a bit more as I have spent the whole weekend trying to get to compile gtk+ ‘normally’ either in cygwin or MYSYS or cmd shell on my Vista machine with no success.
    Here is the output I got:
    <<<<<<>>>>>>>>
    Gtk+ & gtkmm seems too much for Windows & me!
    Anyway thanks for your help 🙂

  10. OOPS!
    My last post left off the output!
    I will try again to show it:

    Dad@DAD-PC /c/gtk_mingw_tutorial/gtk_mingw_tutorial
    $ make
    gcc hello.c `pkg-config –cflags –libs gtk+-2.0` -mwindows -c #Create .o
    hello.c:15:2: warning: no newline at end of file
    gcc.exe: -lgtk-win32-2.0: linker input file unused because linking not done
    gcc.exe: -lgdk-win32-2.0: linker input file unused because linking not done
    gcc.exe: -latk-1.0: linker input file unused because linking not done
    gcc.exe: -lgio-2.0: linker input file unused because linking not done
    gcc.exe: -lgdk_pixbuf-2.0: linker input file unused because linking not done
    gcc.exe: -lpangowin32-1.0: linker input file unused because linking not done
    gcc.exe: -lgdi32: linker input file unused because linking not done
    gcc.exe: -lpangocairo-1.0: linker input file unused because linking not done
    gcc.exe: -lpango-1.0: linker input file unused because linking not done
    gcc.exe: -lcairo: linker input file unused because linking not done
    gcc.exe: -lgobject-2.0: linker input file unused because linking not done
    gcc.exe: -lgmodule-2.0: linker input file unused because linking not done
    gcc.exe: -lglib-2.0: linker input file unused because linking not done
    gcc.exe: -lintl: linker input file unused because linking not done
    gcc hello.o `pkg-config –cflags –libs gtk+-2.0` -mwindows -o hello.exe #Link .
    o
    rm hello.o #Remove .o

    Dad@DAD-PC /c/gtk_mingw_tutorial/gtk_mingw_tutorial
    $ hello

    Hope that shows the output & posts alright!

  11. 11 ildar

    I get the following output:

    $ make
    gcc hello.c `pkg-config –cflags –libs gtk+-2.0` -mwindows -c #Create .o
    hello.c:15:2: warning: no newline at end of file
    gcc.exe: -lgtk-win32-2.0: linker input file unused because linking not done
    gcc.exe: -lgdk-win32-2.0: linker input file unused because linking not done
    gcc.exe: -latk-1.0: linker input file unused because linking not done
    gcc.exe: -lgio-2.0: linker input file unused because linking not done
    gcc.exe: -lgdk_pixbuf-2.0: linker input file unused because linking not done
    gcc.exe: -lpangowin32-1.0: linker input file unused because linking not done
    gcc.exe: -lgdi32: linker input file unused because linking not done
    gcc.exe: -lpangocairo-1.0: linker input file unused because linking not done
    gcc.exe: -lpango-1.0: linker input file unused because linking not done
    gcc.exe: -lcairo: linker

    hello.exe runs without problems either from MSYS console or from Windows explorer. All .lib files mentioned above are in \MinGW\lib directory. Is it normal? Can I fix these messages?

  12. 12 S31

    Note that the download location for GTK+ has changed to:

    http://www.gtk.org/download/index.php

    From here, as of the time of this response, versions are available for GNU/Linux/Unix, 32-bit and 64-bit Windows, and Mac OS X at the respective links.

  13. I’ve got a problen during extracting the GTK++ files into the MinGW directory. It asks to replace files with the same name. No surprises there. What should I do? Please help. I’m totally lost

  14. I followed your directions and it worked perfectly. I did, however, include the mingw and msys bin path in the environment variable path. In response to jeewanthabandara, I replace everything and it worked fine.

    ajs

  15. 15 Carroll

    The challenges cropping up with these x86 deployments included Low infrastructure utilization, Increasing
    physical infrastructure costs and IT management
    costs, insufficient failover and disaster protection, and high
    maintenance enterprise and end-user desktops. ‘We encourage all voters
    who believe in free and fair elections to download the app and keep up with election integrity in real
    time. The app also lets you jump directly to a page in a long document.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: