0
votes

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.

1
I seem to have found a workaround, but it doesn't explain why the command works for some, and not others. I really would like to understand what the issue is. Here is a link to the page I found. stackoverflow.com/questions/19325552/…Jillinger
Your problem is not the pkg-config command but the usage of the result. Under Linux the command is enclosed in backticks to make the shell execute it and replace it with the result of the command. I don't know if this is possible under Windows as well. You might try to store outout of pkg-config in a variable and use that in your command line as suggested in the link you mentioned in previous commentGerhardh
I thought those backticks were strange to windows. I couldn't even make them. I had to copy and paste. Yes, I used the method from the original - stackoverflow.com/questions/1450445/…, and that got rid of those errors. I got other errors, but I'll try to work those out.Jillinger

1 Answers

0
votes

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%