Author Topic: How to Configure Code::Blocks GTK MinGW Project  (Read 55060 times)

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
How to Configure Code::Blocks GTK MinGW Project
« on: June 18, 2012, 05:34:47 pm »
Directions on my way of Configuring an Code::Blocks GTK MinGW GCC Project in Windows 7.
NOTE: I have never compiled any GTK project except for the CB Sample project.
NOTE: Used Code::Blocks 10.05 and MinGW GCC version 4.6.2 from I believe mingw.org

Steps are finished; I might need to add detail for each step; these directions use the GTK pkg-config command.

1. Download gtk+-bundle_2.24.10-20120208_win32.zip (all-in-one bundle) from http://www.gtk.org/download/win32.php
2. Extract in into a folder; in my case C:\apps\gtk+-bundle_2.24.10-20120208_win32
3. Add the bin folder to system path C:\apps\gtk+-bundle_2.24.10-20120208_win32\bin
4. Verify that the system path was updated and pkg-config works.
4a. Open command prompt box/window
4b. Enter command below
Code
pkg-config --cflags gtk+-2.0
My results
Code
-mms-bitfields -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/gtk-2.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/lib/gtk-2.0/include -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/atk-1.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/cairo -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/gdk-pixbuf-2.0 -IC:/appsgtk+-bundle_2.24.10-20120208_win32/include/pango-1.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/glib-2.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/lib/glib-2.0/include -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include -IC:/appsgtk+-bundle_2.24.10-20120208_win32/include/freetype2 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/libpng14
5. Removed step 5; because it was not needed.
6. Use CB Wizard to create GTK sample project; I used "C:/apps/gtk+-bundle_2.24.10-20120208_win32" as GTK path
7. Edit the sample project to use pkg-config instead of the wizard search paths and libraries
7a. Clear the list of link libraries.
7b. Add `pkg-config --libs gtk+-2.0` to other linker options
7c. Clear search directories for Linker and Compiler
7d. Clear the option -mms-bitfields from Compiler settings other options
7e. Add `pkg-config --cflags gtk+-2.0` to Compiler settings other options

8. Build the sample project
Things to check if it failed to build
Did you remember to use the correct slanted single tick mark around the other option commands.
Try saving the project and restarting Code::Blocks.
Verify the full build log shows the correct paths.



Here's is my full build command; edit updated this code block. It was using the wrong paths.
(I had a prior gtk installation from a month ago and the pkg-config found it).
Code
-------------- Build: Debug in testgtk ---------------

mingw32-gcc.exe -Wall -mms-bitfields -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/gtk-2.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/lib/gtk-2.0/include -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/atk-1.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/cairo -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/gdk-pixbuf-2.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/pango-1.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/glib-2.0 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/lib/glib-2.0/include -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/freetype2 -IC:/apps/gtk+-bundle_2.24.10-20120208_win32/include/libpng14     -g     -c C:\Users\tsta8844\Downloads\testgtk\main.c -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\testgtk.exe obj\Debug\main.o   -LC:/apps/gtk+-bundle_2.24.10-20120208_win32/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    

Attached a 7-zip version of the modified project with main.c

Tim S.
« Last Edit: June 18, 2012, 09:28:07 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline sklimkin

  • Single posting newcomer
  • *
  • Posts: 9
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #1 on: June 18, 2012, 11:18:19 pm »
Once again thanks for your attention and angelic patience Tim!

I have understood all (anyway I so I think) from your explanations and an example.
This example successfully works in CodeBlocks: it is compiled, executed.

More difficult examples aren't compiled, but it most likely problems GTK+, instead of CodeBlocks.
I was surprised only with that these difficult examples were compiled out of CodeBlocks - from command line Windows.

I once again will adjust the project on these steps (1,2,3,...,8) and once again I will compile programs-examples.
But in it perhaps already there is no special necessity: it is necessary to talk to developers GTK+, you are right.

Sergey.

Offline sklimkin

  • Single posting newcomer
  • *
  • Posts: 9
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #2 on: June 21, 2012, 10:31:37 pm »
I have anew configured CodeBlocks under recommendations Tim S.

Here an example of test program UIManager
The example is fulfilled after adjustment CodeBlocks specified in the previous message stahta01.
In archive of 4 directories (4 variants of an example):
1. linux CodeBlocks
2. linux console
3. win32 CodeBlocks
4. win32 console

The example is taken from the old textbook on GTK, but the program after an output remained in memory.
Therefore I a little it have corrected and have added the code for switching demonstration between windows and and an output of the most simple in GTK MessageBox.
Compilation win32 console hasn't turned out only because now in system variable PATH there are missing path's to important for compilation and the assembly to libraries.
I will correct a bit later.

But as a whole recommendations stahta01 are fulfilled also result is received.
See:
http://www.mediafire.com/?33yaa8d3coa6b0s
or attachment zip-file.

Once again thanks Tim S.

[attachment deleted by admin]

kvn

  • Guest
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #3 on: October 16, 2013, 04:56:56 pm »
thanks but i am getting a lot of errors after i build sample program..

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #4 on: October 16, 2013, 06:12:41 pm »
thanks but i am getting a lot of errors after i build sample program..

You do realize error messages are information that you should post if you really want help, don't you?
(I suggest posting the first 12 errors and warnings; post at least the first 3 errors in case you have a lot of warnings.)

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
http://wiki.codeblocks.org/index.php?title=FAQ-Issues_and_Workarounds#Q:_I_posted_on_the_forums_that_Code::Blocks_was_not_working.2C_but_no_one_could_help_me.3F

Tim S.
« Last Edit: October 16, 2013, 06:53:02 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline codecub

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #5 on: January 04, 2014, 07:39:04 pm »
thanks but i am getting a lot of errors after i build sample program...
...

@stahta01: Hopefully you, or somebody in the knowledge, is still watching. Here are my error messages, please help:

Code
-------------- Build: Debug in gtkCodelocks01 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\gtk\lib -o bin\Debug\gtkCodelocks01.exe obj\Debug\main.o  -LC:/gtk/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl   
obj\Debug\main.o: In function `helloWorld':
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:8: undefined reference to `gtk_window_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:8: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:8: undefined reference to `gtk_message_dialog_new'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:9: undefined reference to `gtk_window_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:9: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:9: undefined reference to `gtk_window_set_position'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:10: undefined reference to `gtk_dialog_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:10: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:10: undefined reference to `gtk_dialog_run'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:11: undefined reference to `gtk_widget_destroy'
obj\Debug\main.o: In function `main':
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:21: undefined reference to `gtk_false'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:21: undefined reference to `g_log_set_handler'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:22: undefined reference to `gtk_init_abi_check'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:23: undefined reference to `g_log_default_handler'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:23: undefined reference to `g_log_set_handler'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:26: undefined reference to `gtk_window_new'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:27: undefined reference to `gtk_container_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:27: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:27: undefined reference to `gtk_container_set_border_width'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:28: undefined reference to `gtk_window_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:28: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:28: undefined reference to `gtk_window_set_title'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:29: undefined reference to `gtk_window_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:29: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:29: undefined reference to `gtk_window_set_position'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:30: undefined reference to `gtk_widget_realize'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:31: undefined reference to `gtk_main_quit'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:31: undefined reference to `g_signal_connect_data'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:34: undefined reference to `gtk_vbox_new'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:35: undefined reference to `gtk_container_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:35: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:35: undefined reference to `gtk_container_add'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:37: undefined reference to `gtk_button_new_from_stock'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:38: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:38: undefined reference to `g_signal_connect_data'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:39: undefined reference to `gtk_box_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:39: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:39: undefined reference to `gtk_box_pack_start'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:41: undefined reference to `gtk_button_new_from_stock'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:42: undefined reference to `gtk_main_quit'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:42: undefined reference to `g_signal_connect_data'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:43: undefined reference to `gtk_box_get_type'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:43: undefined reference to `g_type_check_instance_cast'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:43: undefined reference to `gtk_box_pack_start'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:46: undefined reference to `gtk_widget_show_all'
G:/User/bue/Desktop/GTK/gtkCodelocks01/main.c:47: undefined reference to `gtk_main'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
46 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Hi, I am a Code::Blocks newbie. Just followed your instructions here. I use Windows 8 64bit, CodeBlocks 13.12, from: codeblocks-13.12mingw-setup.exe and  GTK from gtk+-bundle_2.16.6-20100208_win64.zip. I used used CB Wizard to create the GTK sample project.

Why do I get these error messages? And what can I do about it?

Thanks,

codecub

P.S. I have no problem with the same program and Code::Blocks on Ubuntu 12.04 64 bit.  And on Windows 8, I can comnpile and run this program (the main.c file) correctly in Cygwin's Xserver-Window.


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #6 on: January 04, 2014, 07:47:18 pm »
You're not linking the gtk library, -lgtk is missing from the linker's command line.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #7 on: January 04, 2014, 10:24:02 pm »

@stahta01: Hopefully you, or somebody in the knowledge, is still watching. Here are my error messages, please help:


Hi, I am a Code::Blocks newbie. Just followed your instructions here. I use Windows 8 64bit, CodeBlocks 13.12, from: codeblocks-13.12mingw-setup.exe and  GTK from gtk+-bundle_2.16.6-20100208_win64.zip. I used used CB Wizard to create the GTK sample project.

Why do I get these error messages? And what can I do about it?

Thanks,

codecub

P.S. I have no problem with the same program and Code::Blocks on Ubuntu 12.04 64 bit.  And on Windows 8, I can comnpile and run this program (the main.c file) correctly in Cygwin's Xserver-Window.



FYI: The Compiler shipped with Code::Blocks is a 32-bit only Compiler!

Is there any reason you think gtk+-bundle_2.16.6-20100208_win64.zip will work with it?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline codecub

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #8 on: January 04, 2014, 11:08:44 pm »
...
FYI: The Compiler shipped with Code::Blocks is a 32-bit only Compiler!

Is there any reason you think gtk+-bundle_2.16.6-20100208_win64.zip will work with it?

Tim S.

Thanks, Tim, for guiding a 32/64bit dumbhead! Just replaced  gtk+-bundle_2.16.6-20100208_win64.zip with gtk+-bundle_2.24.10-20120208_win32.zip, and Code::Blocks does GTK like a genie  :)

P.S. I saved your Code::Block modifications in Project > Build options; could I do it permanently in Settings > Compiler without harming future non-GTK projects? This would spare me to do the modifications over and over in each new GTK project.

Siggi

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #9 on: January 05, 2014, 12:04:48 am »
You can create a stub gtk-project and do the setup so it fits your needs, and then save it as user template ("File -> Save project as user template")  and reuse it via "File -> New -> From template" .

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #10 on: January 05, 2014, 12:15:51 am »
Another option is to modify the gtk wizard script and make it suit your needs.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline codecub

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #11 on: January 05, 2014, 11:50:12 am »
Thanks! I'll stick with the template stuff, for the time being.

Another related newbie question: how can I avoid the Win8 console window that opens with the GTK Gui? Is it a CB thing or C programming stuff?

Offline codecub

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: How to Configure Code::Blocks GTK MinGW Project
« Reply #12 on: January 07, 2014, 09:47:16 pm »
Quote
...how can I avoid the Win8 console window that opens with the GTK Gui? Is it a CB thing or C programming stuff?

Found it! Though I chose the GUI "GTK" Project, I still have to change Project > Properties > Build options from console to GTK