{"id":1601,"date":"2022-08-30T15:17:53","date_gmt":"2022-08-30T15:17:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/gtk-gcc-undefined-reference-to-all-gtk-functions-when-linking-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:53","modified_gmt":"2022-08-30T15:17:53","slug":"gtk-gcc-undefined-reference-to-all-gtk-functions-when-linking-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/gtk-gcc-undefined-reference-to-all-gtk-functions-when-linking-collection-of-common-programming-errors\/","title":{"rendered":"GTK+ gcc: undefined reference to all gtk functions when linking-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m coding an interface with GTK+ for chat using XMPP protocol. My code worked fine when I compiled it like :<\/p>\n<pre><code>gcc login_gtk.c `pkg-config --cflags --libs gtk+-3.0`\n<\/code><\/pre>\n<p>But since I add my file to my project, and I&#8217;m using a Makefile, it doesn&#8217;t compile anymore. I guess the problem comes from my Makefile.<\/p>\n<p>Compiler errors :<\/p>\n<pre><code>gcc -o -W -Wall -Wextra -Werror -g -I.\/Includes\/. -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\/freetype2 -I\/usr\/include\/pixman-1 -I\/usr\/include\/libpng12  -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     -c -o Sources\/login_gtk.o Sources\/login_gtk.c\ngcc -o -W -Wall -Wextra -Werror -g -I.\/Includes\/. -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\/freetype2 -I\/usr\/include\/pixman-1 -I\/usr\/include\/libpng12  -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     -c -o Sources\/circular_buffer.o Sources\/circular_buffer.c\ngcc -o -W -Wall -Wextra -Werror -g -I.\/Includes\/. -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\/freetype2 -I\/usr\/include\/pixman-1 -I\/usr\/include\/libpng12  -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     -c -o Sources\/welcome_server.o Sources\/welcome_server.c\ngcc -o -W -Wall -Wextra -Werror -g -I.\/Includes\/. -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\/freetype2 -I\/usr\/include\/pixman-1 -I\/usr\/include\/libpng12  -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     -c -o Sources\/main_loop.o Sources\/main_loop.c\ngcc -o -W -Wall -Wextra -Werror -g -I.\/Includes\/. -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\/freetype2 -I\/usr\/include\/pixman-1 -I\/usr\/include\/libpng12  -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     -c -o Sources\/client_init.o Sources\/client_init.c\ngcc -o -W -Wall -Wextra -Werror -g -I.\/Includes\/. -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\/freetype2 -I\/usr\/include\/pixman-1 -I\/usr\/include\/libpng12  -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     -c -o Sources\/main.o Sources\/main.c\ngcc -o x2p .\/Sources\/login_gtk.o .\/Sources\/circular_buffer.o .\/Sources\/welcome_server.o .\/Sources\/main_loop.o .\/Sources\/client_init.o .\/Sources\/main.o -lexpat\n.\/Sources\/login_gtk.o: In function `login_form':\n.\/Sources\/login_gtk.c:10: undefined reference to `gtk_entry_new'\n.\/Sources\/login_gtk.c:11: undefined reference to `gtk_entry_get_type'\n.\/Sources\/login_gtk.c:11: undefined reference to `g_type_check_instance_cast'\n.\/Sources\/login_gtk.c:11: undefined reference to `gtk_entry_set_text'\n.\/Sources\/login_gtk.c:12: undefined reference to `gtk_box_get_type'\n.\/Sources\/login_gtk.c:12: undefined reference to `g_type_check_instance_cast'\n.\/Sources\/login_gtk.c:12: undefined reference to `gtk_box_pack_start'\n.\/Sources\/login_gtk.c:13: undefined reference to `gtk_entry_get_type'\n.\/Sources\/login_gtk.c:13: undefined reference to `g_type_check_instance_cast'\n<\/code><\/pre>\n<p>Makefile:<\/p>\n<pre><code>NAME            =       x2p\n\nSRCS            =                                   \\\n                    .\/Sources\/login_gtk.c           \\\n                    .\/Sources\/circular_buffer.c     \\\n                    .\/Sources\/welcome_server.c      \\\n                    .\/Sources\/main_loop.c           \\\n                    .\/Sources\/client_init.c         \\\n                    .\/Sources\/main.c                \\                                                                                                      \nOBJS            =       $(SRCS:.c=.o)\n\nCC              =       gcc -o\n\nCFLAGS          =       -W -Wall -Wextra -Werror -g -I.\/Includes\/. $(shell pkg-config --cflags --libs gtk+-3.0)\n\nLDFLAGS         +=      -lexpat\n\nRM              =       rm -f\n\nCAR             =       *\\# *~ *core*\n\nall             :       $(NAME)\n\n$(NAME)         :       $(OBJS)\n                        $(CC) $(NAME) $(OBJS) $(LDFLAGS)\nclean           :\n                        $(RM) $(OBJS) $(CAR)\n\nfclean          :       clean\n                        $(RM) $(NAME)\n\nre              :       fclean all\n<\/code><\/pre>\n<p>And part of login_gtk.c:<\/p>\n<pre><code>#include        \n\n\nvoid            location_form(GtkWidget *pVBox)\n{\n  GtkWidget     *pList;\n\n  pList = gtk_combo_box_text_new();\n  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pList), \"LOCATION\");\n  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pList), \"WORK\");\n  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pList), \"HOME\");\n  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pList), \"SCHOOL\");\n  gtk_combo_box_set_active(GTK_COMBO_BOX(pList), 0);\n  gtk_box_pack_start (GTK_BOX(pVBox), pList, FALSE, TRUE, 0);\n}\n<\/code><\/pre>\n<ol>\n<li>\n<p>The order is wrong: this is an incredibly common mistake I continue to meet. Previous versions of <code>gcc<\/code> were less pick on the argument order and this spread the wrong idea <code>--cflags --libs<\/code> together should work.<\/p>\n<p>Check out this email for info on proper flags ordering.<\/p>\n<\/li>\n<li>\n<p>You haven&#8217;t included the libraries in your Makefile.<\/p>\n<p>You must add <code>-L<\/code><\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:00:55. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m coding an interface with GTK+ for chat using XMPP protocol. My code worked fine when I compiled it like : gcc login_gtk.c `pkg-config &#8211;cflags &#8211;libs gtk+-3.0` But since I add my file to my project, and I&#8217;m using a Makefile, it doesn&#8217;t compile anymore. I guess the problem comes from my Makefile. Compiler errors [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1601","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1601"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1601\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}