-
Notifications
You must be signed in to change notification settings - Fork 7
Instructions
This document shows you how to build GTK+ and its dependencies from scratch on Windows, and use it.
Well first of all, you have to set up your tools. So, the first step
1. Setup a building environment.
After that, just
2. Build GTK+ and its dependencies.
and
3. Use it.
- Make sure there is no folder named
msysorMinGWin your C:\. - Clone this repository.
- Start a Windows command prompt as an administrator.
- From the root directory of this project, run
setup.bat. Please follow the instructions and don't do this by right clicking and selecting "Run as Administrator".
You should reboot your computer to make the installation of font DroidSans take effect.
- Start a msys shell as an administrator. You can do this by right clicking on
C:\msys\msys.batand chooseRun as administrator. - Change the working directory of said msys shell to
libs. - Type
./DOWNLOAD_ALL.shand hit Enter. Let it download source code tarballs. - Prepare a movie and a cup of tea, and maybe some cookies, then type
./BUILD_ALL.shand hit Enter. - Watch the movie. Allow your PC a few hours to build them.
- Check the log files in
libs/logs. See if there's anything wrong.
The files you want are already in C:\msys\opt.
- Write your own GTK+ or gtkmm (or both) source code.
- Open a Windows command prompt. Administrative privileges not needed.
- Type
set PATH=C:\msys\opt\bin;C:\MinGW\bin;%PATH%and press Enter. This will allow you to use MinGW GCC and GTK+/gtkmm within the lifespan of this command prompt. If you've moved these files after building GTK+, change the locations correspondingly. - Write a makefile.
- Build the application from your source code.
- Run the application.
####Here's a minimal working example of GTK+.
Source code below. Save it as gtk_example.c.
#include <gtk/gtk.h>
int main(int argc, char * argv[])
{
gtk_init(&argc, &argv);
GtkWindow * Window_main = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
g_signal_connect(Window_main, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show(GTK_WIDGET(Window_main));
gtk_main();
return 0;
}
Makefile below. Save it as Makefile_gtk.
CC=gcc
CFLAGS=$(shell pkg-config --cflags gtk+-3.0)
LDLIBS=$(shell pkg-config --libs gtk+-3.0)
SOURCE=gtk_example.c
BIN=gtk_example.exe
$(BIN): $(SOURCE)
$(CC) $(CFLAGS) $(SOURCE) -o $(BIN) $(LDLIBS)
Put these two files in the same folder. Change the working directory of the said command prompt to said folder. Type mingw32-make -f Makefile_gtk in the command prompt and press Enter. So the compilation starts. After that, type gtk_example.exe and press Enter, you should see a blank GTK+ window, if everything goes well.
####Here's a minimal working example for gtkmm.
Source code below. Save it as gtkmm_example.cpp.
#include <gtkmm.h>
int main(int argc, char * argv[])
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv);
Gtk::Window Window_main;
return app->run(Window_main);
}
Makefile below. Save it as Makefile_gtkmm.
CXX=g++
CXXFLAGS=$(shell pkg-config --cflags gtkmm-3.0)
LDLIBS=$(shell pkg-config --libs gtkmm-3.0)
SOURCE=gtkmm_example.cpp
BIN=gtkmm_example.exe
$(BIN): $(SOURCE)
$(CXX) $(CXXFLAGS) $(SOURCE) -o $(BIN) $(LDLIBS)
Build and run it like how you build and run the example of GTK+ above.
If you have encountered any problem, please go to FAQ