Fail to compile gtk3 both in msys2 and cmd

You can use Markdown to prevent Discourse from formatting what you type. I put a Markdown “code fence” around most of your quote. Therefore, only the last line is formatted.

Either my eyesight is bad, or you typed the command perfectly. It should have worked! So, let’s compare your MSys2 with mine.

I typed the following commands:

Gregory MINGW64 /tmp
$ type gcc
gcc is /mingw64/bin/gcc

Gregory MINGW64 /tmp
$ pkg-config --cflags gtk+-3.0
-IC:/msys64/mingw64/include/gtk-3.0 -IC:/msys64/mingw64/include/pango-1.0 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include/libpng16 -mms-bitfields -IC:/msys64/mingw64/include/fribidi -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include/lzo -IC:/msys64/mingw64/include/pixman-1 -mms-bitfields -mms-bitfields -mms-bitfields -mms-bitfields -mms-bitfields -mms-bitfields -mms-bitfields -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 -mms-bitfields -mms-bitfields -mms-bitfields -IC:/msys64/mingw64/include/atk-1.0 -mms-bitfields -mms-bitfields -mms-bitfields -pthread -mms-bitfields

Gregory MINGW64 /tmp
$ ls /mingw64/include/gtk-3.0
gdk/  gtk/

Gregory MINGW64 /tmp
$ ls /mingw64/include/gtk-3.0/gtk
a11y/                   gtkcelleditable.h          gtkentrybuffer.h            gtkgrid.h             gtkorientable.h             gtksearchentry.h         gtktexttag.h
deprecated/             gtkcelllayout.h            gtkentrycompletion.h        gtkheaderbar.h        gtkoverlay.h                gtkselection.h           gtktexttagtable.h
gtk.h                   gtkcellrenderer.h          gtkenums.h                  gtkicontheme.h        gtkpadcontroller.h          gtkseparator.h           gtktextview.h
gtk-a11y.h              gtkcellrendereraccel.h     gtkeventbox.h               gtkiconview.h         gtkpagesetup.h              gtkseparatormenuitem.h   gtktogglebutton.h
gtkaboutdialog.h        gtkcellrenderercombo.h     gtkeventcontroller.h        gtkimage.h            gtkpaned.h                  gtkseparatortoolitem.h   gtktoggletoolbutton.h
gtkaccelgroup.h         gtkcellrendererpixbuf.h    gtkeventcontrollerkey.h     gtkimcontext.h        gtkpapersize.h              gtksettings.h            gtktoolbar.h
gtkaccellabel.h         gtkcellrendererprogress.h  gtkeventcontrollermotion.h  gtkimcontextinfo.h    gtkplacessidebar.h          gtkshortcutlabel.h       gtktoolbutton.h
gtkaccelmap.h           gtkcellrendererspin.h      gtkeventcontrollerscroll.h  gtkimcontextsimple.h  gtkplug.h                   gtkshortcutsgroup.h      gtktoolitem.h
gtkaccessible.h         gtkcellrendererspinner.h   gtkexpander.h               gtkimmodule.h         gtkpopover.h                gtkshortcutssection.h    gtktoolitemgroup.h
gtkactionable.h         gtkcellrenderertext.h      gtkfilechooser.h            gtkimmulticontext.h   gtkpopovermenu.h            gtkshortcutsshortcut.h   gtktoolpalette.h
gtkactionbar.h          gtkcellrenderertoggle.h    gtkfilechooserbutton.h      gtkinfobar.h          gtkprintcontext.h           gtkshortcutswindow.h     gtktoolshell.h
gtkadjustment.h         gtkcellview.h              gtkfilechooserdialog.h      gtkinvisible.h        gtkprintoperation.h         gtkshow.h                gtktooltip.h
gtkappchooser.h         gtkcheckbutton.h           gtkfilechoosernative.h      gtklabel.h            gtkprintoperationpreview.h  gtksizegroup.h           gtktreednd.h
gtkappchooserbutton.h   gtkcheckmenuitem.h         gtkfilechooserwidget.h      gtklayout.h           gtkprintsettings.h          gtksizerequest.h         gtktreemodel.h
gtkappchooserdialog.h   gtkclipboard.h             gtkfilefilter.h             gtklevelbar.h         gtkprogressbar.h            gtksocket.h              gtktreemodelfilter.h
gtkappchooserwidget.h   gtkcolorbutton.h           gtkfixed.h                  gtklinkbutton.h       gtkradiobutton.h            gtkspinbutton.h          gtktreemodelsort.h
gtkapplication.h        gtkcolorchooser.h          gtkflowbox.h                gtklistbox.h          gtkradiomenuitem.h          gtkspinner.h             gtktreeselection.h
gtkapplicationwindow.h  gtkcolorchooserdialog.h    gtkfontbutton.h             gtkliststore.h        gtkradiotoolbutton.h        gtkstack.h               gtktreesortable.h
gtkaspectframe.h        gtkcolorchooserwidget.h    gtkfontchooser.h            gtklockbutton.h       gtkrange.h                  gtkstacksidebar.h        gtktreestore.h
gtkassistant.h          gtkcolorutils.h            gtkfontchooserdialog.h      gtkmain.h             gtkrecentchooser.h          gtkstackswitcher.h       gtktreeview.h
gtk-autocleanups.h      gtkcombobox.h              gtkfontchooserwidget.h      gtkmenu.h             gtkrecentchooserdialog.h    gtkstatusbar.h           gtktreeviewcolumn.h
gtkbbox.h               gtkcomboboxtext.h          gtkframe.h                  gtkmenubar.h          gtkrecentchoosermenu.h      gtkstylecontext.h        gtktypebuiltins.h
gtkbin.h                gtkcontainer.h             gtkgesture.h                gtkmenubutton.h       gtkrecentchooserwidget.h    gtkstyleprovider.h       gtktypes.h
gtkbindings.h           gtkcssprovider.h           gtkgesturedrag.h            gtkmenuitem.h         gtkrecentfilter.h           gtkswitch.h              gtkversion.h
gtkborder.h             gtkcsssection.h            gtkgesturelongpress.h       gtkmenushell.h        gtkrecentmanager.h          gtktestutils.h           gtkviewport.h
gtkbox.h                gtkdebug.h                 gtkgesturemultipress.h      gtkmenutoolbutton.h   gtkrender.h                 gtktextattributes.h      gtkvolumebutton.h
gtkbuildable.h          gtkdialog.h                gtkgesturepan.h             gtkmessagedialog.h    gtkrevealer.h               gtktextbuffer.h          gtkwidget.h
gtkbuilder.h            gtkdnd.h                   gtkgesturerotate.h          gtkmodelbutton.h      gtkscale.h                  gtktextbufferrichtext.h  gtkwidgetpath.h
gtkbutton.h             gtkdragdest.h              gtkgesturesingle.h          gtkmodules.h          gtkscalebutton.h            gtktextchild.h           gtkwindow.h
gtkcalendar.h           gtkdragsource.h            gtkgesturestylus.h          gtkmountoperation.h   gtkscrollable.h             gtktextdisplay.h         gtkwindowgroup.h
gtkcellarea.h           gtkdrawingarea.h           gtkgestureswipe.h           gtknativedialog.h     gtkscrollbar.h              gtktextiter.h            gtkx.h
gtkcellareabox.h        gtkeditable.h              gtkgesturezoom.h            gtknotebook.h         gtkscrolledwindow.h         gtktextlayout.h          gtkx-autocleanups.h
gtkcellareacontext.h    gtkentry.h                 gtkglarea.h                 gtkoffscreenwindow.h  gtksearchbar.h              gtktextmark.h

The first gcc flag that pkg-config shows is the Windows path to that header. I confirmed that the file exists by listing that (MSys) path. Then, I listed the path in the #include <gtk/gtk.h> line. The header is the first file in the directory listing.

Please type the four commands that I typed. See if your output matches mine.

Thank you for your info. I managed to fix it today. I have to install the msys2 in my E:\msys64. I used to install this in E:\Program Files (x86)\msys64. I think the reason is that the folder has space in its name which pkg-config doesn’t recognize.

I still have no idea on how to use the markdown here.

A new problem for compiling the code.

Daniel@DESKTOP-RDDFVF2 MINGW64 /g/document/C++C/gtkLearn1
# gcc `pkg-config --cflags gtk+-3.0` main.c `pkg-config --libs gtk+-3.0`
In file included from E:/msys64/mingw64/include/glib-2.0/gobject/gobject.h:28,
                 from E:/msys64/mingw64/include/glib-2.0/gobject/gbinding.h:29,
                 from E:/msys64/mingw64/include/glib-2.0/glib-object.h:22,
                 from E:/msys64/mingw64/include/glib-2.0/gio/gioenums.h:28,
                 from E:/msys64/mingw64/include/glib-2.0/gio/giotypes.h:28,
                 from E:/msys64/mingw64/include/glib-2.0/gio/gio.h:26,
                 from E:/msys64/mingw64/include/gtk-3.0/gdk/gdkapplaunchcontext.h:28,
                 from E:/msys64/mingw64/include/gtk-3.0/gdk/gdk.h:32,
                 from E:/msys64/mingw64/include/gtk-3.0/gtk/gtk.h:30,
                 from main.c:3:
main.c: In function 'main':
main.c:31:22: warning: implicit declaration of function 'GTK_OBJECT'; did you mean 'ATK_OBJECT'? [-Wimplicit-function-declaration]
   31 |     g_signal_connect(GTK_OBJECT(button), "Clicked", G_CALLBACK(greet), "button");
      |                      ^~~~~~~~~~
E:/msys64/mingw64/include/glib-2.0/gobject/gsignal.h:508:29: note: in definition of macro 'g_signal_connect'
  508 |     g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
      |                             ^~~~~~~~
main.c:31:22: warning: passing argument 1 of 'g_signal_connect_data' makes pointer from integer without a cast [-Wint-conversion]
   31 |     g_signal_connect(GTK_OBJECT(button), "Clicked", G_CALLBACK(greet), "button");
E:/msys64/mingw64/include/glib-2.0/gobject/gsignal.h:508:29: note: in definition of macro 'g_signal_connect'
  508 |     g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
      |                             ^~~~~~~~
E:/msys64/mingw64/include/glib-2.0/gobject/gsignal.h:404:67: note: expected 'gpointer' {aka 'void *'} but argument is of type 'int'
  404 | gulong   g_signal_connect_data                (gpointer           instance,
      |                                                ~~~~~~~~~~~~~~~~~~~^~~~~~~~
E:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:\msys64\tmp\ccBD0vFw.o:main.c:(.text+0x10d): undefined reference to `GTK_OBJECT'
collect2.exe: error: ld returned 1 exit status

Are you copy-pasting code from GTK2 examples? Because they won’t work in GTK3.

For instance, GtkObject does not exist in GTK3; and you should have never used a cast to GtkObject as the first argument to g_signal_connect() in the first place.

You should pass the object instance, as is, i.e.

g_signal_connect (button, "clicked", G_CALLBACK (greet), "button");

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.