在Windows 10的MinGW中编译GTK + -2.0程序(带有MSYS)

时间:2018-09-23 22:26:08

标签: c windows gcc mingw32 gtk2

我有一个可以在Linux上完美编译的程序,直到我将GTK添加到它(它使用了ncurses)之前,它还可以在Windows中与MinGW(带有MSYS)一起完美编译。

我从https://sourceforge.net/projects/gtk-mingw/files/gtk%2B2/下载了gtk+-2.24.11-1-bundle.7z

我将其提取到C:\MinGW中,以替换所有需要替换的内容。

这是主Makefile的一部分:

################################################################################
# executables

ifeq ($(OS), linux)
  BIN_NAME  = mine-sweeper
else ifeq ($(OS), win)
  BIN_NAME  = mine-sweeper.exe
endif

export  BIN_NAME

################################################################################
# Make variables (CC, etc...)
ifeq ($(OS), linux)
  CC        = gcc
  LD        = ld
else ifeq ($(OS), win)
  CC        = gcc.exe
  LD        = ld.exe
endif

export  CC
export  LD

################################################################################
CFLAGS      = -std=c11
CFLAGS         += `pkg-config --cflags gtk+-2.0`

GTK_LIBS    = `pkg-config --libs gtk+-2.0`
ifeq ($(OS), linux)
  CFLAGS       += -D OS_LINUX

  LIBS      = -l m -l ncursesw $(GTK_LIBS)
else ifeq ($(OS), win)
  CFLAGS       += -D OS_WIN
  # curses
  CFLAGS       += -D _XOPEN_SOURCE=500 -I /mingw/include/ncursesw -I /mingw/include

  CURSES_LIBS   = -L /mingw/lib -l ncursesw -l psapi
  LIBS      = -static -l m $(CURSES_LIBS) $(GTK_LIBS)
endif

export  CFLAGS
export  LIBS

和失败的Makefile:

MAIN_OBJ_LIBALX = alx_lib.o
MAIN_OBJ_ABOUT  = about_mod.o
MAIN_OBJ_CTRL   = ctrl_mod.o
MAIN_OBJ_GAME   = game_mod.o
MAIN_OBJ_MENU   = menu_mod.o
MAIN_OBJ_PLAY   = player_mod.o
MAIN_OBJ_SAVE   = save_mod.o
MAIN_OBJ_XYZZY  = xyzzy_mod.o
MAIN_OBJS   = $(OBJ_DIR)/main.o \
            $(patsubst %,$(LIBALX_OBJ_DIR)/%,$(MAIN_OBJ_LIBALX)) \
            $(patsubst %,$(ABOUT_OBJ_DIR)/%,$(MAIN_OBJ_ABOUT)) \
            $(patsubst %,$(CTRL_OBJ_DIR)/%,$(MAIN_OBJ_CTRL)) \
            $(patsubst %,$(GAME_OBJ_DIR)/%,$(MAIN_OBJ_GAME)) \
            $(patsubst %,$(MENU_OBJ_DIR)/%,$(MAIN_OBJ_MENU)) \
            $(patsubst %,$(PLAY_OBJ_DIR)/%,$(MAIN_OBJ_PLAY)) \
            $(patsubst %,$(SAVE_OBJ_DIR)/%,$(MAIN_OBJ_SAVE)) \
            $(patsubst %,$(XYZZY_OBJ_DIR)/%,$(MAIN_OBJ_XYZZY))

$(BIN_NAME): $(MAIN_OBJS)
    $(Q)$(CC) $^ -o $@ $(LIBS)

似乎可以编译.c文件没有问题,但是在make的最后阶段存在问题:

~/mine-sweeper$ make OS=win
\tCC    alx_cmp.o
\tCC    alx_file.o
\tCC    alx_input.o
\tCC    alx_mask.o
\tCC    alx_math.o
\tCC    alx_ncur.o
\tCC    alx_seed.o
\tLD    alx_lib.o

\tCC    about.o
\tLD    about_mod.o

\tCC    start.o
\tLD    ctrl_mod.o

\tCC    game.o
\tCC    game_iface.o
\tLD    game_mod.o

\tCC    parser.o
\tCC    menu_iface.o
\tCC    menu_clui.o
\tCC    menu_tui.o
\tCC    menu_gui.o
\tLD    menu_mod.o

\tCC    player_iface.o
\tCC    player_clui.o
\tCC    player_tui.o
\tCC    player_gui.o
\tLD    player_mod.o

\tCC    save.o
\tCC    score.o
\tLD    save_mod.o

\tCC    xyzzy.o
\tLD    xyzzy_mod.o

\tCC    main.o

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgtk-win32-2.0
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgdk-win32-2.0
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -latk-1.0
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgio-2.0
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgdk_pixbuf-2.0
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lfreetype
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lfontconfig
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lgobject-2.0
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lglib-2.0
collect2.exe: error: ld returned 1 exit status
make[1]: *** [mine-sweeper.exe] Error 1
make: *** [binary] Error 2

我想念什么?

编辑: 我还从相同的sourceforge链接下载了gtk+-2.24.11-binwin32-1.7z,并将其提取到MinGW的根目录中,然后再次尝试,结果相同。

将捆绑包提取到MinGW的根目录中是否正确,还是应该将其放入MinGW的某个子目录中?


已解决: 已安装MSYS2,该软件包具有gtk2软件包,并且所有内容均可编译,并且还可以针对x86或x64安装。

1 个答案:

答案 0 :(得分:0)

您正在尝试链接到32位捆绑软件,但未下载win32捆绑软件。您要么要使用64位mingw进行构建,要么要获取gtk堆栈的mingw32捆绑包。