User forums > General (but related to Code::Blocks)

Compiling GTK+ Apps with CB

<< < (2/3) > >>

stahta01:
If this is a valid path to a valid file
C:\MinGW\include\gtk-2.0\gtk\gtk.h

Then

--- Quote from: Dead1nside on October 23, 2006, 03:38:11 pm ---
--- Code: (c) ---#include <gtk/gtk.h>
--- End code ---

--- End quote ---

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


--- Quote from: Dead1nside 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>
--- End code ---
"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:

--- End quote ---

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

MortenMacFly:

--- Quote from: Dead1nside on October 23, 2006, 03:38:11 pm ---mingw32-gcc.exe: C:\MinGW\include\gtk-2.0\gtk: linker input file unused because linking not done

--- End quote ---
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.

Dead1nside:
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.

Dead1nside:
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.
--- End quote ---

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;
}
--- End code ---

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.

MortenMacFly:

--- Quote from: Dead1nside on October 24, 2006, 01:38:46 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.
--- End quote ---

--- End quote ---
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).


--- Quote from: Dead1nside on October 24, 2006, 01:38:46 am ---gtk-win32-2.0.lib and libgtk-win32-2.0.dll.a

--- End quote ---
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.


--- Quote from: Dead1nside on October 24, 2006, 01:38:46 am ---cc1.exe: error: unrecognized command line option "-flibs"
mingw32-gcc.exe: `pkg-config: No such file or directory

--- End quote ---
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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version