简体   繁体   English

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

[英]Compile GTK+-2.0 program in MinGW (with MSYS) for Windows 10

I have a program which compiles perfectly in Linux, and until I added GTK to it (it used ncurses), it also compiled perfectly in Windows with MinGW (with MSYS). 我有一个可以在Linux上完美编译的程序,直到我向其中添加了GTK(它使用了ncurses),它也已经在Windows中与MinGW(带有MSYS)一起完美编译。

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

I extracted it to C:\\MinGW replacing everything that asked to replace. 我将其提取到C:\\MinGW替换了所有需要替换的内容。

Here is a part of the main Makefile: 这是主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

and the Makefile that fails: 和失败的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)

It seems to compile .c files without problems, but there are problems in the final stage of the make: 似乎可以编译.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

What am I missing? 我想念什么?

EDIT: I also downloaded gtk+-2.24.11-binwin32-1.7z from the same sourceforge link, and extracted it into the root dir of MinGW and tried again with the same result. 编辑:我还从同一sourceforge链接下载了gtk+-2.24.11-binwin32-1.7z ,并将其提取到MinGW的根目录中,然后再次尝试以相同的结果。

Is it right to extract the bundle into the root dir of MinGW, or should it go in some subdir of MinGW? 将包提取到MinGW的根目录中是正确的,还是应该将其放入MinGW的某个子目录中?


SOLVED: Installed MSYS2, which has a package for gtk2, and everything compiles, and can also install for x86 or x64. 已解决:已安装MSYS2,该软件包具有gtk2软件包,并且所有内容均可编译,并且还可以针对x86或x64安装。

You are trying to link to a 32 bit bundle but did not download the win32 bundle. 您正在尝试链接到32位捆绑软件,但未下载win32捆绑软件。 You either want to build with a 64 bit mingw or get the mingw32 bundle of the gtk stack. 您要么要使用64位mingw进行构建,要么要获取gtk堆栈的mingw32捆绑包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM