Compiling GTK-app in c with cygwin: invalid argument - c

I thought everything was ok since I installed
MinGW
gtk3
gtkmm
cygWin
And I have no problem to compile ordinary simple files. Neither do I have problem with commands such as
$ pkg-config --cflags --libs gtk+-2.0
it outputs
-mms-bitfields -IC:/gtkmm/include/gtk-2.0 -IC:/gtkmm/lib/gtk-2.0/include
- IC:/gtkmm/include/atk-1.0 -IC:/gtkmm/include/cairo -IC:/gtkmm/include/gdk-pixbuf
-2.0 - IC:/gtkmm/include/pango-1.0 -IC:/gtkmm/include/glib-2.0 -IC:/gtkmm/lib/glib
-2.0/include -IC:/gtkmm/include -IC:/gtkmm/include/freetype2
-IC:/gtkmm/include/libpng14 -LC:/gtkmm/lib -Lc:/devel/dist/win32/libpng-1.4.3-1/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 -lpng14 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule
-2.0 -lgthread-2.0 -lglib-2.0 -lintl
But when I try to compile a simple gtk-app from a tutorial with
$ gcc c_gui.c -o c_gui `pkg-config --cflags --libs gtk+-2.0`
I get an error from the cygwin terminalwindow:
:gcc.exe: error: -LC:/gtkmm/lib: Invalid argument
What could possibly be wrong?

Something seems to be wrong with your pkgconfig. It shouldn't be returning DOS style paths. If I run your exact command above, I get:
-D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/libpng15 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/harfbuzz -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lpangocairo-1.0 -lXinerama -lXi -lXrandr -lXcursor -lXcomposite -lgdk_pixbuf-2.0 -lpangoft2-1.0 -lgio-2.0 -lcairo -lpixman-1 -lGL -lpthread -lxcb-shm -lxcb-render -lXrender -lXext -lXdamage -lX11-xcb -lxcb-glx -lXfixes -lX11 -lxcb -lXau -lXdmcp -lharfbuzz -lpango-1.0 -lfontconfig -lgmodule-2.0 -lgobject-2.0 -lffi -lglib-2.0 -lintl -liconv -lpcre -lexpat -lfreetype -lbz2 -lpng15 -lm -lz
I suspect it's because you're trying to mix MinGW and Cygwin. They don't always work well together.
My /usr/lib/pkgconfig/gtk+-2.0.pc looks like this:
prefix=/usr
exec_prefix=/usr
libdir=/usr/lib
includedir=${prefix}/include
target=x11
gtk_binary_version=2.10.0
gtk_host=x86_64-unknown-cygwin
Name: GTK+
Description: GTK+ Graphical UI Library (${target} target)
Version: 2.24.23
Requires: gdk-${target}-2.0 atk cairo gdk-pixbuf-2.0 gio-2.0 pangoft2
Libs: -L${libdir} -lgtk-${target}-2.0
Cflags: -I${includedir}/gtk-2.0
which looks reasonable to me.

Related

linking error. Perhaps a problem with ordering?

I'm building a program which uses GTK+3 and pango. Most of it compiles fine apart from the last bit which builds the executable. The final command is:
gcc -o z80sim main.c -Wall -Iz80 -Igui obj/disas.o obj/iosim.o obj/sim0.o obj/sim1.o obj/sim2.o obj/sim3.o obj/sim4.o obj/sim5.o obj/sim6.o obj/sim7.o obj/simctl.o obj/simfun.o obj/simglb.o obj/simint.o obj/callbacks.o obj/code.o obj/guiglb.o obj/memory.o obj/flags.o obj/log.o obj/ports.o obj/registers.o `pkg-config --cflags --libs gtk+-3.0`
But I get this error message:
obj/sim1.o: In function `cpu':
sim1.c:(.text+0x2cb): undefined reference to `check_gui_break'
obj/callbacks.o: In function `on_open1_activate':
callbacks.c:(.text+0x20): undefined reference to `Get_File'
:
:
Where check_gui_break is defined and called in sim1.c etc.
This has to be something to do with the ordering of object files and libraries on the ld call, but I have tried putting the pkg-config part before and after the individual .o files and it still gives the same errors.
I've read the very informative https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking but, although I know a lot more now, I still can't crack this one.
BTW.
pkg-config --cflags --libs gtk+-3.0
gives
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0
Please will some kind soul take pity on me and enlighten me?
It appears that most of the errors I've encountered have been a result of the transition from Glade2 to Glade3. In 2, Glade generates some C code which is what's missing from my code. Back to the reference manual to see how to modernise the code.

How do I solve the gcc error on finding pkg-config?

This question seems to have been asked a zillion times, but unfortunately, none of the answers helped me.
I believe I have installed gtk correctly. My pkg-config environment seems okay. I'm not so sure of gcc.
I removed all the mingw and cygwin folders from my path environment, as I am only going to be using msys2 packages. So I have my path environment this way:-
GTK_LIB_DIR
C:\msys64\mingw64\lib
PKG_CONFIG_PATH
C:\msys64\mingw64\lib\pkgconfig
Path - C:\msys64\usr\bin;C:\msys64\mingw64\bin;%GTK_LIB_DIR%
The problem I am having is with compilation. Running this...
gcc pkg-config --cflags gtk+-3.0 -o gtkTest C:\dev\test_gtk3.c pkg-config --libs gtk+-3.0
I get...
cc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: unrecognized command line option '--cflags'
gcc: error: unrecognized command line option '--libs'
I can run the following commands separately, with expected results. e.g.
pkg-config --cflags gtk+-3.0
pkg-config --libs gtk+-3.0
gcc -o gtkTest C:\dev\test_gtk3.c
Of course the last command returns an error, since gtk is not referenced.
I tried various combinations, some of my own. Some recommended, but one error persists, on pkg-config.
e.g.
C:\WINDOWS\system32>gcc -o gtkTest C:\dev\test_gtk3.c "pkg-config --cflags gtk+-3.0 pkg-config --libs gtk+-3.0"
gcc: error: pkg-config --cflags gtk+-3.0 pkg-config --libs gtk+-3.0: No such file or directory
The last answer I found says "If pkg-config reports that it couldn't find the package, then you didn't install the Gtk development package as offered by your Linux distribution."
I'm using Windows, but I think I installed gtk correctly, since I followed the instructions, and I get what seems to be the expected results (please correct me if I am mistaken).
C:\WINDOWS\system32>pkg-config --cflags gtk+-3.0
-pthread -mms-bitfields -I/mingw64/include/gtk-3.0 -I/mingw64/include/cairo -I/m
ingw64/include -I/mingw64/include/pango-1.0 -I/mingw64/include/fribidi -I/mingw6
4/include -I/mingw64/include/atk-1.0 -I/mingw64/include/cairo -I/mingw64/include
/pixman-1 -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include -I/
mingw64/include/harfbuzz -I/mingw64/include -I/mingw64/include/libpng16 -I/mingw
64/include/gdk-pixbuf-2.0 -I/mingw64/include -I/mingw64/lib/libffi-3.2.1/include
-I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include
C:\WINDOWS\system32>pkg-config --libs gtk+-3.0
-L/mingw64/lib -L/mingw64/lib/../lib -L/mingw64/lib -lgtk-3 -lgdk-3 -lz -lgdi32
-limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lep
oxy -lopengl32 -lgdi32 -lpangocairo-1.0 -lm -lgdi32 -lpangoft2-1.0 -lm -lpangowi
n32-1.0 -lm -lusp10 -lgdi32 -lpango-1.0 -lm -lfribidi -lthai -ldatrie -latk-1.0
-lcairo-gobject -lcairo -lz -lpixman-1 -lm -pthread -lfontconfig -liconv -lexpat
-lfreetype -lbz2 -lharfbuzz -lm -lusp10 -lgdi32 -lrpcrt4 -lgraphite2 -lpng16 -l
z -lgdk_pixbuf-2.0 -lm -lgio-2.0 -pthread -lintl -lshlwapi -ldnsapi -liphlpapi -
lws2_32 -lgmodule-2.0 -pthread -lintl -lz -lgobject-2.0 -pthread -lintl -lffi -l
glib-2.0 -lintl -lws2_32 -lole32 -lwinmm -lshlwapi -pthread -lm -lpcre
C:\WINDOWS\system32>gcc -o gtkTest C:\dev\test_gtk3.c | pkg-config --cflags --libs gtk+-3.0
-pthread -mms-bitfields -I/mingw64/include/gtk-3.0 -I/mingw64/include/cairo -I/m
ingw64/include -I/mingw64/include/pango-1.0 -I/mingw64/include/fribidi -I/mingw6
4/include -I/mingw64/include/atk-1.0 -I/mingw64/include/cairo -I/mingw64/include
/pixman-1 -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include -I/
mingw64/include/harfbuzz -I/mingw64/include -I/mingw64/include/libpng16 -I/mingw
64/include/gdk-pixbuf-2.0 -I/mingw64/include -I/mingw64/lib/libffi-3.2.1/include
-I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include
-L/mingw64/lib -L/mingw64/lib/../lib -L/mingw64/lib -lgtk-3 -lgdk-3 -lz -lgdi32
-limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lep
oxy -lopengl32 -lgdi32 -lpangocairo-1.0 -lm -lgdi32 -lpangoft2-1.0 -lm -lpangowi
n32-1.0 -lm -lusp10 -lgdi32 -lpango-1.0 -lm -lfribidi -lthai -ldatrie -latk-1.0
-lcairo-gobject -lcairo -lz -lpixman-1 -lm -pthread -lfontconfig -liconv -lexpat
-lfreetype -lbz2 -lharfbuzz -lm -lusp10 -lgdi32 -lrpcrt4 -lgraphite2 -lpng16 -l
z -lgdk_pixbuf-2.0 -lm -lgio-2.0 -pthread -lintl -lshlwapi -ldnsapi -liphlpapi -
lws2_32 -lgmodule-2.0 -pthread -lintl -lz -lgobject-2.0 -pthread -lintl -lffi -l
glib-2.0 -lintl -lws2_32 -lole32 -lwinmm -lshlwapi -pthread -lm -lpcre
C:\dev\test_gtk3.c:1:10: fatal error: gtk/gtk.h: No such file or directory
1 | #include <gtk/gtk.h>
| ^~~~~~~~~~~
compilation terminated.
Has anyone here struggled with this for hours, like I have, and finally got to understand what the problem is.
Please share your solution. Thank you.
Using this Installing gtk and compiling using gcc under windows? helped me get past the errors.
I used the following suggestion.
"Instead of a batch file, you may find more convenient to create an
user environmental variable and store the flags in there, that way you
will be able to compile from within a normal command prompt."
So I created two new environment variables (e.g. GTK_FLAGS_VARS; GTK_LIBS_VARS), and pasted the outputs in the variable values. Then in path place %GTK_FLAGS_VARS%;%GTK_LIBS_VARS%
Afterward gcc -o gtkTest C:\dev\test_gtk3.c %GTK_FLAGS_VARS% %GTK_LIBS_VARS%

How to use GTK C library?

I'm new at C and started to learn how to create GUI.
For some reason the only way program run is
gcc simple.c -o simple -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12
If i just run gcc simple.cit gives me
In file included from /usr/include/glib-2.0/glib/galloca.h:32:0,
from /usr/include/glib-2.0/glib.h:30,
from /usr/include/glib-2.0/gobject/gbinding.h:28,
from /usr/include/glib-2.0/glib-object.h:23,
from /usr/include/glib-2.0/gio/gioenums.h:28,
from /usr/include/glib-2.0/gio/giotypes.h:28,
from /usr/include/glib-2.0/gio/gio.h:26,
from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
from /usr/include/gtk-2.0/gdk/gdk.h:32,
from /usr/include/gtk-2.0/gtk/gtk.h:32,
from graphical.c:1:/usr/include/glib-2.0/glib/gtypes.h:32:24: fatal error: glibconfig.h: No such file or catalog compilation terminated.
If I do other 'traditional' ways to include lib:
gcc `pkg-config gtk+-2.0 --cflags` example.c -o example `pkg-config gtk+-2.0 --libs`
It gives me:
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc' to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
graphical.c:1:21: fatal error: gtk/gtk.h: No such file or catalog
What is the right way to include GTK?
I just figured out what was the problem.
I had linuxbrew installed and for some reason pkg-config took path from one of it's repos even if I force it to export.
I completely removed linuxbrew and now it's finally working!

How to link to "Eye of Gnome" library?

Here is the command I use:
gcc -w -g -export-dynamic -o "%e" prog.c `pkg-config --cflags --libs gtk+-3.0 ` `pkg-config --cflags --libs eog`
My program compiles but I get errors from the linker:
undefined reference to `eog_image_new'
Here is the output of pkg-config --cflags --libs eog
pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/eog-3.0 -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0

gcc raises "unrecognized command line option" error with pkg-config

I am trying to compile a gtk program using the tutorial here. When I issue the command
gcc -o tut tut.c $(pkg-config --cflags --libs gtk+-2.0 gmodule-2.0)
I get the following error:
gcc: error: unrecognized command line option ‘-pthread -I/usr/include/gtk-2.0
-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0
-I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0
-I/usr/include/gio-unix-2.0/ -I/usr/include/freetype2 -I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
-I/usr/include/libpng12 -I/usr/include/harfbuzz -Wl,--export-dynamic -pthread
-lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0
-lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lfreetype
-lgmodule-2.0 -lglib-2.0 ’
gcc is version 4.8.2. pkg-config is version 0.26. i have libgtk2.0-dev installed.
I can compile simple c programs fine.
How do I resolve the "unrecognized command" problem?
[update from comment]
I am using zsh.
This looks like a shell issue.
What shell are you using?
In case it's not bash, give bash a try.

Resources