如何在MSYS2中设置SDL2?我收到错误 "undefined reference to 'WinMain'"

How to set up SDL2 in MSYS2? I get error "undefined reference to 'WinMain'"

$ make
g++ main.cpp -I/mingw/include -L/mingw/lib -w -Wall -lSDL2main -lSDL2 -o test
/usr/lib/../lib/libmsys-2.0.a(libcmain.o): In function `main':
/msys_scripts/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain'
/msys_scripts/msys2-runtime/src/msys2-runtime/winsup/cygwin/lib/libcmain.c:37:(.text.startup+0x94): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain'
collect2: error: ld returned 1 exit status

Mingw 教程和我的区别在于'-lmingw32'选项。

但是MSYS2中没有'mingw32'文件

如何解决?

有 2 个版本或 gcc 工具链:类似 Cygwin msys/gcc 和原生 mingw-w64-i686-gccmingw-w64-x86_64-gcc.

在您的情况下,您需要安装 mingw-w64-* 工具链并根据架构使用 MINGW32 或 MINGW64 shell。