Compilation- GTK+ programs in Win32 environment 10.06.2012 SNK
--------------------------------------------------------------
(thanks © 2006-2007 Andrey Borovsky <anb @ symmetrica.net>):
------------------------------------------------------------
In Linux creation of programs with use of GTK library rather clearly and simply.
It is possible to use Code::Blocks together with Glade, is possible without Glade, and it is possible and without Code:: Blocks - to do everything in the gedit editor, and then to compile in the terminal.
But in Windows setup Code:: Blocks project for operation with the compiler gcc and GTK+ library isn't so simple and clear.
Therefore I decided to compile programs examples using command line in KMD.EXE
hello c++ console example
-------------------------
1. write text in file main.cpp
#include <cstdio>
int main()
{
printf("Hello World !\nHello GCC !\nHello ALL !"); return 0;
}
2. open c:\Windows\system32\cmd.exe (console-analog) & write command
3.
run in console compiled main_cpp.exe and see output:
Hello World !
Hello GCC !
Hello ALL !
hello gcc console example
-------------------------
1. write text in file main.c
#include <io.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
printf("Hello World !\nHello GCC !\nHello ALL !");
return 0;
}
2. open c:\Windows\system32\cmd.exe (console-analog) & write command
C:\projects\GTK\testGCC>gcc -o main main.c
main.c:2:21: error: cstdlib.h: No such file or directory
main.c:3:20: error: cstdio.h: No such file or directory
main.c: In function 'main':
main.c:9: warning: incompatible implicit declaration of built-in function 'printf'
2a.
System-variable PATH is:
C:\projects\GTK\testGCC>PATH
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\CodeBlocks\MinGW\bin
2b.
System-variable PATH shall be corrected - add next:
C:\projects\GTK\testGCC>SET PATH=%PATH%;C:\GTK+\bin;C:\GTK+\lib;C:\GTK+\include;C:\GTK+\lib\pkgconfig
and next:
C:\projects\GTK\testGCC>SET PATH=%PATH%;C:\Program Files\CodeBlocks\MinGW\lib;C:\Program Files\CodeBlocks\MinGW\include
System-variable PATH is corrected - see NOW:
C:\projects\GTK\testGCC>PATH
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\CodeBlocks\MinGW\bin;C:\GTK+\bin;C:\GTK+\lib;C:\GTK+\include;C:\GTK+\lib\pkgconfig;C:\Program Files\CodeBlocks\MinGW\lib;C:\Program Files\CodeBlocks\MinGW\include
2c.
C:\projects\GTK\testGCC>gcc -Wall -g main.c -o main_C
3.
run in console compiled main_C.exe and see output:
Hello World !
Hello GCC !
Hello ALL !
-------------------------------------------------------------------------------
HelloGTK example - GTK-window (Solid nut or HARD CORE!!!):
----------------------------------------------------------
0. !ATTENTION! You shall have the installed package "GTK+ bounle for Win32"
1. write text in file helloGTK.c (from every sample - see Internet)
GTK-program has string:
<-- it is main problem for linking-compiling !!!
2. open c:\Windows\system32\cmd.exe (console-analog) & write command
C:\projects\GTK\testGCC>gcc -o helloGTK helloGTK.c
(or maybe C:\projects\GTK\testGCC>gcc -o main main.c)
helloGTK.c:2:21: error: gtk/gtk.h: No such file or directory
( !!! gtk/gtk.h - is problem !!!)
... ... ... and so on - many error-strings ...
2a. then write command
C:\projects\GTK\testGCC>gcc -Wall -g helloGTK.c -o helloGTK
helloGTK.c:2:21: error: gtk/gtk.h: No such file or directory
( !!! gtk/gtk.h - is problem !!!)
... ... ... and so on - many error-strings ...
2b. then write Linux-lyke command
C:\projects\GTK\testGCC>gcc -Wall -g helloGTK.c -o helloGTK `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`
gcc: `pkg-config: No such file or directory
gcc: gtk+-2.0`: No such file or directory
gcc: `pkg-config: No such file or directory
gcc: gtk+-2.0`: No such file or directory
cc1.exe: error: unrecognized command line option "-fcflags"
cc1.exe: error: unrecognized command line option "-flibs"
2c.
(on HDD-drive exists C:\GTK+\lib\pkgconfig\ or maybe C:\Program Files\CodeBlocks\MinGW\lib\pkgconfig\)
SET PATH=%PATH%;C:\GTK+\lib\pkgconfig
2c1. - check installed GTK+ libraries:
C:\projects\GTK\testGCC>pkg-config --libs gtk+-2.0
-LC:/GTK+/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
2c2. - check installed GTK+ includes (flags):
C:\projects\GTK\testGCC>pkg-config --cflags gtk+-2.0
-mms-bitfields -IC:/GTK+/include/gtk-2.0 -IC:/GTK+/lib/gtk-2.0/include -IC:/GTK+/include/atk-1.0 -IC:/GTK+/include/cairo -IC:/GTK+/include/gdk-pixbuf-2.0 -IC:/GTK+/include/pango-1.0 -IC:/GTK+/include/glib-2.0 -IC:/GTK+/lib/glib-2.0/include -IC:/GTK+/include -IC:/GTK+/include/freetype2 -IC:/GTK+/include/libpng14
2c3. run CMD.EXE 2c4. insert IN ONE STRING includes & libs and run command:
gcc -Wall helloGTK.c -o helloGTK -mms-bitfields -IC:/GTK+/include/gtk-2.0 -IC:/GTK+/lib/gtk-2.0/include -IC:/GTK+/include/atk-1.0 -IC:/GTK+/include/cairo -IC:/GTK+/include/gdk-pixbuf-2.0 -IC:/GTK+/include/pango-1.0 -IC:/GTK+/include/glib-2.0 -IC:/GTK+/lib/glib-2.0/include -IC:/GTK+/include -IC:/GTK+/include/freetype2 -IC:/GTK+/include/libpng14 -LC:/GTK+/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
or if Your file named main.c
gcc -Wall main.c -o main -mms-bitfields -IC:/GTK+/include/gtk-2.0 -IC:/GTK+/lib/gtk-2.0/include -IC:/GTK+/include/atk-1.0 -IC:/GTK+/include/cairo -IC:/GTK+/include/gdk-pixbuf-2.0 -IC:/GTK+/include/pango-1.0 -IC:/GTK+/include/glib-2.0 -IC:/GTK+/lib/glib-2.0/include -IC:/GTK+/include -IC:/GTK+/include/freetype2 -IC:/GTK+/include/libpng14 -LC:/GTK+/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
As a result in the current folder it is possible to see the file "helloGTK.exe" (or "main.exe") - that is windows32 working executable file.
2c5. run command helloGTK (or main):
C:\projects\GTK\testGCC>helloGTK
You shall see a window of your GTK program.
That is all !!!
-------------------------------------------------------------------------------
PostScriptum:
GTK+ is free sotware
The free software in the Windows environment will have the price in the form of libraries which are necessary for putting to your program if you want that the program was executed on any other computer.
In Windows static compilation of the program with GTK libraries is almost impossible.
Therefore it is necessary to write down the following files in the folder of the program:
libgtk-win32-2.0-0.dll
libgdk-win32-2.0-0.dll
libcairo-2.dll
libgdk_pixbuf-2.0-0.dll
libpangowin32-1.0-0.dll
libpangocairo-1.0-0.dll
libpangoft2-1.0-0.dll
libpango-1.0-0.dll
libgio-2.0-0.dll
libgobject-2.0-0.dll
libgthread-2.0-0.dll
libgmodule-2.0-0.dll
libglib-2.0-0.dll
libatk-1.0-0.dll
freetype6.dll
intl.dll
zlib1.dll
libpng14-14.dll
libgcc_s_dw2-1.dll
libfontconfig-1.dll
-------------------
All (20 files) size of: 12963 KB (!!!)Without them no GTK program will work.
It is useful to familiarize with license conditions of GTK previously.Download some examples at:
http://www.mediafire.com/?w9w485myfw8z3ib