User forums > Help
Code::Blocks and GTK+ compile-link in Windows over KMD.EXE
sklimkin:
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
--- Code: ---#include <cstdio>
int main()
{
printf("Hello World !\nHello GCC !\nHello ALL !"); return 0;
}
--- End code ---
2. open c:\Windows\system32\cmd.exe (console-analog) & write command
--- Code: ---g++ -o main_cpp main.cpp
--- End code ---
3.
run in console compiled main_cpp.exe and see output:
--- Code: ---Hello World !
Hello GCC !
Hello ALL !
--- End code ---
hello gcc console example
-------------------------
1. write text in file main.c
--- Code: ---#include <io.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
printf("Hello World !\nHello GCC !\nHello ALL !");
return 0;
}
--- End code ---
2. open c:\Windows\system32\cmd.exe (console-analog) & write command
--- Code: ---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'
--- End code ---
2a.
System-variable PATH is:
--- Code: ---C:\projects\GTK\testGCC>PATH
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\CodeBlocks\MinGW\bin
--- End code ---
2b.
System-variable PATH shall be corrected - add next:
--- Code: ---C:\projects\GTK\testGCC>SET PATH=%PATH%;C:\GTK+\bin;C:\GTK+\lib;C:\GTK+\include;C:\GTK+\lib\pkgconfig
--- End code ---
and next:
--- Code: ---C:\projects\GTK\testGCC>SET PATH=%PATH%;C:\Program Files\CodeBlocks\MinGW\lib;C:\Program Files\CodeBlocks\MinGW\include
--- End code ---
System-variable PATH is corrected - see NOW:
--- Code: ---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
--- End code ---
2c.
--- Code: ---C:\projects\GTK\testGCC>gcc -Wall -g main.c -o main_C
--- End code ---
3.
run in console compiled main_C.exe and see output:
--- Code: ---Hello World !
Hello GCC !
Hello ALL !
--- End code ---
-------------------------------------------------------------------------------
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:
--- Code: ---#include <gtk/gtk.h>
--- End code ---
<-- it is main problem for linking-compiling !!!
2. open c:\Windows\system32\cmd.exe (console-analog) & write command
--- Code: ---C:\projects\GTK\testGCC>gcc -o helloGTK helloGTK.c
--- End code ---
(or maybe C:\projects\GTK\testGCC>gcc -o main main.c)
--- Code: ---helloGTK.c:2:21: error: gtk/gtk.h: No such file or directory
--- End code ---
( !!! gtk/gtk.h - is problem !!!)
... ... ... and so on - many error-strings ...
2a. then write command
--- Code: ---C:\projects\GTK\testGCC>gcc -Wall -g helloGTK.c -o helloGTK
helloGTK.c:2:21: error: gtk/gtk.h: No such file or directory
--- End code ---
( !!! gtk/gtk.h - is problem !!!)
... ... ... and so on - many error-strings ...
2b. then write Linux-lyke command
--- Code: ---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"
--- End code ---
2c.
(on HDD-drive exists C:\GTK+\lib\pkgconfig\ or maybe C:\Program Files\CodeBlocks\MinGW\lib\pkgconfig\)
--- Code: ---SET PATH=%PATH%;C:\GTK+\lib\pkgconfig
--- End code ---
2c1. - check installed GTK+ libraries:
--- Code: ---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
--- End code ---
2c2. - check installed GTK+ includes (flags):
--- Code: ---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
--- End code ---
2c3. run CMD.EXE 2c4. insert IN ONE STRING includes & libs and run command:
--- Code: ---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
--- End code ---
or if Your file named main.c
--- Code: ---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
--- End code ---
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):
--- Code: ---C:\projects\GTK\testGCC>helloGTK
--- End code ---
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:
--- Code: ---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
--- End code ---
-------------------
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
stahta01:
Read
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
Note: The above might not apply; but, since I read your post twice and still did not find a clear question. I have to go with the default link that I post.
Tim S.
ollydbg:
I think the OP want to wrote a tutorial.
MortenMacFly:
--- Quote from: ollydbg on June 15, 2012, 03:51:50 am ---I think the OP want to wrote a tutorial.
--- End quote ---
Yes, but a very bad one: Adding include path's to the system's PATH environment is completely bullshit.
sklimkin:
--- Quote from: ollydbg on June 15, 2012, 03:51:50 am ---I think the OP want to wrote a tutorial.
--- End quote ---
Thanks for your notes. It is pleasant to me to see responses of dear developers of Code:: Blocks.
No, it didn't begin the textbook/tutotial, it is an illustration of makeshift of a question of compilation of programs in which GTK+ libraries are used.
Probably not I one experience difficulties in the correct configuration of the project Code::Blocks.
Probably not I one write programs in plain C language (without ++).
After I read forum rules, I was ashamed to ask questions directly.
I do not think that developers of GTK + will want to hear my questions. After all in Linux these libraries normally work, and a porting to Windows - the minor task.
In rules of a forum that discussion of questions connected to the compiler is offtop is strictly specified.
Here I also don't know as well as whom to ask.
But I have a question also the response to it I didn't find neither at a forum nor in other places.
Here my question:
What lines are necessary in a configuration Code::Blocks project OS windows32 for operation with the compiler gcc and to GTK+ libraries and Cairo.
And also (that is very important) where in project settings such lines should be inserted, that compilation of the project was same successful as in OS Linux.
For this purpose I at the end of the message gave the reference to the file archive with examples.
Navigation
[0] Message Index
[#] Next page
Go to full version