Author Topic: Compiling GTK+ Apps with CB  (Read 10250 times)

Offline Dead1nside

  • Single posting newcomer
  • *
  • Posts: 8
Compiling GTK+ Apps with CB
« on: October 19, 2006, 11:25:07 pm »
Hi,

Sorry if this is posted somewhere really obvious and I'm just being blind, but I'm having real trouble in getting C::B to compile programs built with code from the GTK+ 2.0 tutorial. http://www.gtk.org/tutorial/

This could be because I'm pretty new to all of this, but the lack of documentation or any guides to my knowledge is slightly disheartening.

Could someone guide me through it, if not point me in the right direction? I'm using CodeBlocks with MinGW 5.0.2 on Windows XP.

I have installed Glade and GTK using the most current installer from here http://gladewin32.sourceforge.net/modules/news/ .

I also tried following this guide http://www.ibiblio.org/apollo/WinGtkHowto.html and started dragging all the individual files into their respective directories in the c:\MinGw\ folder, but sorting through all those locale folders individually seems like I'm doing it the hard way.

Thanks in advance, would very much appreciate your time and help.

Offline Dead1nside

  • Single posting newcomer
  • *
  • Posts: 8
Re: Compiling GTK+ Apps with CB
« Reply #1 on: October 20, 2006, 08:19:08 pm »
If I have it all installed, do I just need to put the paths to the gtk.h header file etc. if so where? Thanks, just trying to explain myself better.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Compiling GTK+ Apps with CB
« Reply #2 on: October 20, 2006, 08:57:57 pm »
if so where?
Basically yes: You need to provide the compiler with the include path to the GTK headers and the linker with the library patch to the GTK libraries. In addition you need to link your application against the GTK libraries that are required. This depends on your project.
All of this you setup in the project options under "Compiler" and "Linker".
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Dead1nside

  • Single posting newcomer
  • *
  • Posts: 8
Re: Compiling GTK+ Apps with CB
« Reply #3 on: October 21, 2006, 11:05:13 pm »
Thanks, I will try to get the format correct if not, I'll post back. Appreciate the reply.

Offline Dead1nside

  • Single posting newcomer
  • *
  • Posts: 8
Re: Compiling GTK+ Apps with CB
« Reply #4 on: October 23, 2006, 03:38:11 pm »
Hi again,

I've just got round to this again, and I've forgotten what I need and where it needs to go. The include line goes like this

Code: c
#include <gtk/gtk.h>

So I've searched and I've got it installed in two places actually, but the one I should be using is in the "C:\MinGW\include\gtk-2.0\gtk" ?

So I added that to the Build Options of the project under Compiler--->[Other Options] but this gave me:

Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.mingw.org/bugs.shtml> for instructions.
mingw32-gcc.exe: C:\MinGW\include\gtk-2.0\gtk: linker input file unused because linking not done
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings


I'm stuck again, and would appreciate the help. I'm only really used to Delphi, even then I don't mess around with build options much. Thanks in advance.
 

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Compiling GTK+ Apps with CB
« Reply #5 on: October 23, 2006, 04:15:21 pm »
If this is a valid path to a valid file
C:\MinGW\include\gtk-2.0\gtk\gtk.h

Then
Code: c
#include <gtk/gtk.h>

Implies you should have "C:\MinGW\include\gtk-2.0" as an include directory under
"Project" -> "Build Options" -> "Directories" -> "Compiler"

Hi again,

I've just got round to this again, and I've forgotten what I need and where it needs to go. The include line goes like this

Code: c
#include <gtk/gtk.h>
"C:\MinGW\include\gtk-2.0\gtk" ?

So I added that to the Build Options of the project under Compiler--->[Other Options] but this gave me:

You should NOT add folder names under [Other Options] in nearly all cases; please remove and try my above place to add it under "Directories".

Note: Path to libraries go under "Directories" -> "Linker"

Tim S
« Last Edit: October 23, 2006, 04:20:04 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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Compiling GTK+ Apps with CB
« Reply #6 on: October 23, 2006, 04:16:53 pm »
mingw32-gcc.exe: C:\MinGW\include\gtk-2.0\gtk: linker input file unused because linking not done
Oh dear... it seems you are not really used to a build process, right?! ;-)
The include directory (the one that contains the header files) has to be put into the compiler directories. As you include "gtk/gtk.h" you have to add the lower level directory there -> "C:\MinGW\include\gtk-2.0". So much for the compiler part. This ensures that the compiler will find the headers it needs.
Now the linker: Where there is an "include" directory there should also be a "lib" directory (as you need a GTK *sdk* to compile GTK projects). This directory you have to put to linker directories (also in the project options). Then you have to add the libraries you need to link against (I can't tell - but I assume something like "libgtk.a") into the list of libraries to link your project against. Add "gtk" there only, this will resolve on the linker command to "-lgtk" which the linker will resolve to "libgtk.a" finally... trust me, this works.
Keep in mind:
- "Other options" are directly passed to the command line of the compiler/linker and will cause errors if not used correctly. In your case the linker tried to link your project agains a library called "C:\MinGW\include\gtk-2.0\gtk" which of course will fail because this is a directory.
- Don't mix compiler/linker parts. The compiler need header files, the linker libraries. And both need to know where they are.
- Keep in mind that you might need specific defines for the compilation/linking, too. This depends on your project and the GTK libraries
- Ensure you link against all libraries that are required (otherwise you'll receive "undefined symbols" errors). This is at least the "top level" GTK library, but also others might be required - consult the GTK-SDK for information about this (I don't know).
- On windows: Ensure you also link against the system libraries you will require, e.g. user32, gdi32 and others. Again: The information you should be able to get from the GTK-SDK documentation.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Dead1nside

  • Single posting newcomer
  • *
  • Posts: 8
Re: Compiling GTK+ Apps with CB
« Reply #7 on: October 24, 2006, 12:33:34 am »
Thanks, I'm in the process of putting everything you've said into practice. Thanks for your time, I appreciate this. You're right I've only really been used to pressing Ctrl + F9 and then F9 to run.

Offline Dead1nside

  • Single posting newcomer
  • *
  • Posts: 8
Re: Compiling GTK+ Apps with CB
« Reply #8 on: October 24, 2006, 01:38:46 am »
Ok, thanks again for the help here. Documentation seems to be quite thin on the ground here.

I didn't get your last part MortenMacFly, the bit that goes.

Quote
Add "gtk" there only, this will resolve on the linker command to "-lgtk" which the linker will resolve to "libgtk.a" finally... trust me, this works.

Where does that need to go?

So far I've added under Project--> Build Options --> [Directories]

[Compiler] --> C:\MinGW\include\gtk-2.0

and for the Linker

[Linker] --> C:\MinGW\lib

(as the 'gtk-2.0' folder in MinGW/lib/ had no .a or .lib files in.)

And I've added the following libraries under [Linker]:

gtk-win32-2.0.lib and libgtk-win32-2.0.dll.a

With the above options I seem to get a flood of compiler errors, it seems to be going through all the headers in /include/gtk/ and reporting errors in each...

In the basic tutorial (link in the first post) it says I can compile the following code with: 'gcc base.c -o base `pkg-config --cflags --libs gtk+-2.0`'

Code: c
#include <gtk/gtk.h>

int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
   
    gtk_init (&argc, &argv);
   
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_show  (window);
   
    gtk_main ();
   
    return 0;
}

But adding that command line sans the 'gcc' to [Other Options] gets the following:

cc1.exe: error: unrecognized command line option "-flibs"
mingw32-gcc.exe: base.c: No such file or directory
mingw32-gcc.exe: `pkg-config: No such file or directory
mingw32-gcc.exe: gtk+-2.0`: No such file or directory
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings


Am I still missing something fundamental here?

Really appreciate the help. Thanks.
« Last Edit: October 24, 2006, 01:43:25 am by Dead1nside »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Compiling GTK+ Apps with CB
« Reply #9 on: October 24, 2006, 08:39:45 am »
Quote
Add "gtk" there only, this will resolve on the linker command to "-lgtk" which the linker will resolve to "libgtk.a" finally... trust me, this works.
Under project options -> Linker -> Just click "add" and add "libgtk-win32-2.0.dll.a" there, nothing else ("gtk-win32-2.0.dll" should be enough, too - that's what I ment with the statement).

gtk-win32-2.0.lib and libgtk-win32-2.0.dll.a
This very much looks to me as if the SDK provides 2 versions of the GTK library: One for MSVC (the first) and one for MinGW/GCC (the second). Thus, of course you have to use the second only. Start with a C::B GUI project which should setup the project to automatically link against the windows libs (remember: user32, gdi32...), too.

cc1.exe: error: unrecognized command line option "-flibs"
mingw32-gcc.exe: `pkg-config: No such file or directory
You cannot use pkg-config on Win32 unless you have an Win32 implementation for this. This "tool" resolves the required libraries for you, but on Windows you usually have to do this manually. Search with google for GTK + MinGW + GCC or similar.

The problem here is, that you not really know what to link against and whether you have the right or wrong GTK-SDK. You need to clarify this. I recommend a google search as proposed which should reveal the command line parameters (compilation steps) for the gcc on Windows that you can put into C::B. I have no glue about GTK - do for this don't expect too much help from me... ;-)

With regards, Morten.

Ps.: If you post another build log, please enable the "full log" option -> see my sig.

Edit: Typos.
« Last Edit: October 24, 2006, 09:21:05 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ssinfo

  • Single posting newcomer
  • *
  • Posts: 2
Re: Compiling GTK+ Apps with CB
« Reply #10 on: January 21, 2008, 02:09:50 am »
Hi,

after some searching I found how to compile a GTK application in CodeBlocks. I have attached 2 PDF files which explain how to compile GTK applications under Windows and Linux (OpenSuse 10.2).

Sorry for the mistake, English is not my native language.

It may helps somebody..



[attachment deleted by admin]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Compiling GTK+ Apps with CB
« Reply #11 on: January 21, 2008, 08:29:36 am »
It may helps somebody..
Please do *not* cross-post. One post in the right forum is enough (I have removed the other posts). Also please note that we don't have endless disk space. So posting multiple times with an attachment is even worse.
Thanks.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ