tags:

views:

380

answers:

4

Hi Can someone please help me with compiling gtk+ (& gtkmm) at Vista cmd prompt? I have tried recently & cannot get this to work. I feel I have all dependencies and paths correct but I obviously haven't or am missing something! I have searched the internet but haven't found specific help for this (I am also trying to compile in cygwin- but have successfully compiled & run the simple helloworld gtk+ example in MSYS).

I have gcc installed via MinGW & Gtk+ Win32 dev (Glade) & Gtkmm Win32 installed. Here are some sample cmd prompt outputs to show the problems I am getting:

D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>gcc helloworld.c -o hellowo
rld
helloworld.c:1:21: gtk/gtk.h: No such file or directory
helloworld.c:5: error: syntax error before '*' token
helloworld.c:11: error: syntax error before "delete_event"
helloworld.c:11: error: syntax error before '*' token
helloworld.c: In function `delete_event':
helloworld.c:26: error: `TRUE' undeclared (first use in this function)
helloworld.c:26: error: (Each undeclared identifier is reported only once
helloworld.c:26: error: for each function it appears in.)
helloworld.c: At top level:
helloworld.c:30: error: syntax error before '*' token
helloworld.c: In function `main':
helloworld.c:40: error: `GtkWidget' undeclared (first use in this function)
helloworld.c:40: error: `window' undeclared (first use in this function)
helloworld.c:41: error: `button' undeclared (first use in this function)
helloworld.c:48: error: `GTK_WINDOW_TOPLEVEL' undeclared (first use in this func
tion)
helloworld.c:56: error: `NULL' undeclared (first use in this function)
helloworld.c:80: error: `gtk_widget_destroy' undeclared (first use in this funct
ion)

D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>gcc helloworld.c -o hellowo
rld pkg-config --cflags --libs gtk+-2.0
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"

D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>gcc --v
Reading specs from C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --wi
th-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --dis
able-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --d
isable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --with
out-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enabl
e-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)

D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>pkg-config --version
0.23

D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>which pkg-config
/cygdrive/c/Gtk+/bin/pkg-config

D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld> echo %PKG_CONFIG_PATH%
C:\Gtk+\lib\pkgconfig

Is pkg-config installed alright? Am I using the correct compile command syntax? Can I use MS vis C express compiler (or whatever MSWindows7 SDK compiler is-as I also have that installed?!). I am only a beginner/amateur programmer but do want to write gtk+/gtkmm code for GUI programming and would like to be able compile at cmd prompt as well as using IDEs for coding & compiling/running.

I am grateful for and look forward to helpful replies, many thanks

A: 

I would highly recommend CMake for this task. Yes I know that's not what you asked, but you're not even using a makefile. Although I'm sure it is possible to hack some command together that will make it work it's not practical. CMake has built in modules for generating makefiles and finding gtkmm libraries on windows you need. It can even generate MSVC projects or mingw/msys makefiles.
That being said, if you insist on going the hard way, run pkg-config on the gtkmm.pc file with --cflags and COPY PASTE the output into a .bat file. I don't know any other way to embed pkg-config into a windows command line. (I actually did it that way once, it worked)
But seriously, cmake was designed to solve the problem, and it's FOSS.

Chris H
rpd
A: 
D:\RPD_Programming\RPD_HelloWorld\RPD_Gtk_helloworld>gcc helloworld.c -o hellowo
rld pkg-config --cflags --libs gtk+-2.0
  1. You need pkg-config's output as a part of the command like this:

    gcc helloworld.c -o helloworld.exe `pkg-config --cflags --libs gtk+-2.0` 
    

    Also make sure you got pkg-config installed and configured properly.

  2. helloworld.c:1:21: gtk/gtk.h: No such file or directory

    This shows you don't have the GTK headers in the library path

LiraNuna
rpd
A: 

I found an alternative solution from this internet forum: gtk forum -dreblen

Making these env variables for pkg-config --cflags & pkg-config --libs gtk+-2.0 and combining them to a new env var %GTK_COMPILE% and including that in the command line in the Vista cmd shell has worked and the compile completes and the .exe gui window helloworld runs.

I still though do not know why my pkg-version is from MinGW directory and my pkg-config path is C:\Gtk+\lib\pkgconfig.

This is still not the answer I expected and I still feel there should be another (better/proper) way to use pkg-config fully at the cmd prompt in Vista with gtk+ to get a successful compile and run. Maybe one day I will understand this properly!

rpd
A: 

Using pkg-config from cmd.exe is really a pain, as the "normal" way to use it is inside backquotes or backticks (the `thingies, ASCII backquote, don't call them "backslashes") in a Unix style shell. If you insist on using just cmd.exe, you need to do some cmd.exe acrobatics to get the output of pkg-config into the command line. Or just run pkg-config manfually and copy/paste its output into a .bat file that does the build.

Anyway, one important thing to remember is that whenever you see the unfortunately common meme of running pkg-config with both the --cflags and --libs options at the same time (as in LiraNuna's answer above), that in general won't work on Windows.

The order of arguments given to gcc (and cl, for that matter) is important. Libraries should go after the object (or source) files that reference them.

(It just happens to usually work on Linux and other ELF-based systems to do it randomly because executables there can contain undefined symbols.)

So if you have the output of pkg-config --cflags foo in the env var FOO_CFLAGS, and the output of pkg-config --libs foo in the env var FOO_LIBS, the correct way to run gcc would be

gcc %CFLAGS% -o myprog.exe %FOO_CFLAGS% myprog.c %FOO_LIBS% %LIBS%

where CFLAGS are whatever other compiler flags you want to use and LIBS whatever other libraries you need. Add more source or object files as needed, of course.

tml