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