8

XMPP プロトコルを使用して、チャット用の GTK+ とのインターフェイスをコーディングしています。次のようにコンパイルすると、コードは正常に機能しました。

gcc login_gtk.c `pkg-config --cflags --libs gtk+-3.0`

しかし、自分のファイルを自分のプロジェクトに追加し、Makefile を使用しているため、もうコンパイルされません。問題は Makefile にあると思います。

コンパイラ エラー:

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
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/circular_buffer.o Sources/circular_buffer.c
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/welcome_server.o Sources/welcome_server.c
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/main_loop.o Sources/main_loop.c
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/client_init.o Sources/client_init.c
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/main.o Sources/main.c
gcc -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
./Sources/login_gtk.o: In function `login_form':
./Sources/login_gtk.c:10: undefined reference to `gtk_entry_new'
./Sources/login_gtk.c:11: undefined reference to `gtk_entry_get_type'
./Sources/login_gtk.c:11: undefined reference to `g_type_check_instance_cast'
./Sources/login_gtk.c:11: undefined reference to `gtk_entry_set_text'
./Sources/login_gtk.c:12: undefined reference to `gtk_box_get_type'
./Sources/login_gtk.c:12: undefined reference to `g_type_check_instance_cast'
./Sources/login_gtk.c:12: undefined reference to `gtk_box_pack_start'
./Sources/login_gtk.c:13: undefined reference to `gtk_entry_get_type'
./Sources/login_gtk.c:13: undefined reference to `g_type_check_instance_cast'

メイクファイル:

NAME            =       x2p

SRCS            =                                   \
                    ./Sources/login_gtk.c           \
                    ./Sources/circular_buffer.c     \
                    ./Sources/welcome_server.c      \
                    ./Sources/main_loop.c           \
                    ./Sources/client_init.c         \
                    ./Sources/main.c                \                                                                                                      
OBJS            =       $(SRCS:.c=.o)

CC              =       gcc -o

CFLAGS          =       -W -Wall -Wextra -Werror -g -I./Includes/. $(shell pkg-config --cflags --libs gtk+-3.0)

LDFLAGS         +=      -lexpat

RM              =       rm -f

CAR             =       *\# *~ *core*

all             :       $(NAME)

$(NAME)         :       $(OBJS)
                        $(CC) $(NAME) $(OBJS) $(LDFLAGS)
clean           :
                        $(RM) $(OBJS) $(CAR)

fclean          :       clean
                        $(RM) $(NAME)

re              :       fclean all

login_gtk.c の一部:

#include        <gtk/gtk.h>


void            location_form(GtkWidget *pVBox)
{
  GtkWidget     *pList;

  pList = gtk_combo_box_text_new();
  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pList), "LOCATION");
  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pList), "WORK");
  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pList), "HOME");
  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(pList), "SCHOOL");
  gtk_combo_box_set_active(GTK_COMBO_BOX(pList), 0);
  gtk_box_pack_start (GTK_BOX(pVBox), pList, FALSE, TRUE, 0);
}
4

3 に答える 3

8

順序が間違っています : これは、私が遭遇し続けている信じられないほどよくある間違いです。の以前のバージョンでgccは、引数の順序についてそれほどうるさくなく、これにより間違った考えpkgconfig --cflags --libsがあらゆる位置で機能するようになりました。

適切なフラグの順序については、このメールを確認してください。要するに:

gcc $(pkg-config --cflags ...) myapp.c $(pkg-config --libs ...)
于 2013-06-19T20:43:46.927 に答える
0

私は最終的にこのことを行うことでコンパイルに到達します Makefile :

NAME            =       x2p

SRCS            =                                       \
                        ./Sources/circular_buffer.c     \
                        ./Sources/welcome_server.c      \
                        ./Sources/main_loop.c           \
                        ./Sources/client_init.c         \
                        ./Sources/main.c                \                                            

OBJS            =       $(SRCS:.c=.o)

LLFLAGS         =       $(shell pkg-config --cflags --libs gtk+-3.0)

CC              =       gcc

O               =       -o

CFLAGS          =       -W -Wall -Wextra -Werror -g -I./Includes/.


LDFLAGS         +=      -lexpat

RM              =       rm -f

CAR             =       *\# *~ *core*

all             :       $(NAME)

$(NAME)         :       $(OBJS)
                        $(CC) -I./Includes/. ./Sources/login_gtk.c $(LLFLAGS) $(O) $(NAME) $(OBJS) $(LDFLAGS)
clean           :
                        $(RM) $(OBJS) $(CAR)

fclean          :       clean
                        $(RM) $(NAME)

re              :       fclean all
于 2013-06-15T14:18:35.570 に答える