Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

c - Installing gtk and compiling using gcc under windows?

I have gcc installed in c:/programfiles (also set as a path variable), and i have all the necessary files for gtk from http://www.gtk.org/download-windows.html, glib,gtk,pango,atk and cairo. Although I have no clue as to how to compile a c program using gtk with the gcc compiler. How do I set everything up so that it works?. (I don't know where each zip file goes.?) basically I don't really know where start.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Ok, to install and use GTK+ in Windows and use it with MinGW you may follow these steps for example. I'll try to made them the easy, don't worry:

  1. Install MinGW, as you've already done it so I wont elaborate this step.
  2. Download the GTK+ all-in-one bundle (there may be things you may not use... but this way should work).
  3. Decompress the contents of the bundle, you may do it in the same folder MinGW is installed or do it in another folder, it doesn't matter.
  4. Launch a command prompt, get to the bin directory where you extracted the bundle and run:

    pkg-config --cflags --libs gtk+-win32-2.0

  5. It will print a list of compilation flags, and libraries to link your project to. Now, copy them and create a batch file (.bat or Windows Command Script .cmd) with the following:

    set VAR=FLAGS
    start cmd

    Where VAR is a name of a variable (for example GTK) and FLAGS is the output of the previous command (pkg-config).

  6. Whenever you want to compile something that uses GTK+ double click that file, the GTK+ flags will be in VAR. You may compile this way for example:

    gcc foo.c %VAR%

Instead of a batch file, you may find more convenient to create an user environmental variable and store the flags in there, that way you will be able to compile from within a normal command prompt. I didn't describe that because the way to do it varies depending on the version of Windows you have. Generally you may find it in advanced system properties.

Once you are more confident in GTK+ programming you may not use all of the packages, or all the flags, or reorder them in a different manner, use makefiles instead of having the compilation flags and the libraries in an environmental variable, ...

But by now, this will get you started.

Also, you'll be linking dynamically to GTK+, so either the proper libraries are in the same directory of your project or are accessible from the path when you want to run it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...