简体   繁体   中英

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).

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

I extracted it to C:\\MinGW replacing everything that asked to replace.

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

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:

~/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.

Is it right to extract the bundle into the root dir of MinGW, or should it go in some subdir of MinGW?


SOLVED: Installed MSYS2, which has a package for gtk2, and everything compiles, and can also install for x86 or x64.

You are trying to link to a 32 bit bundle but did not download the win32 bundle. You either want to build with a 64 bit mingw or get the mingw32 bundle of the gtk stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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