mingw-w64 和 SDL2 链接问题
issue with mingw-w64 and SDL2 linking
我正在尝试遵循 SDL 教程并编译使用 SDL 的 c++ 文件。我在 windows 10,最初使用的是 MinGW。
过了某个时间点,我意识到我的 MinGW 安装出现了与 SDL 无关的问题,所以我改用 MinGW-w64,这解决了非 SDL 问题,但现在当我尝试使用 SDL 编译任何东西时,它找不到 lSDL2 或 lSDL2main。但是,它确实会跳过各种文件,说它们不兼容。
我怀疑这可能是 32 bit/64 位不兼容,但我不确定这是怎么回事,因为即使我明确确保使用 32 位 g++ 编译器,问题仍然存在。作为参考,我输入命令提示符的命令是
x86_64-w64-mingw32-g++ 04_key_presses.cpp
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses
错误信息是
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib\libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.dll.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib\libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.dll.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
您的编译器是x86_64-w64-mingw32-g++
。那是 64 位编译器。
32 位编译器是 i686-w64-mingw32-g++.exe
。 64 位链接
您正在尝试:
x86_64-w64-mingw32-g++ 04_key_presses.cpp \
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w \
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses
跳过不兼容的 32 位 SDL2 库。
64 位编译器可以构建 64 位或 32 位目标,构建
默认为 64 位。要针对 32 位,请为两个编译传递 -m32
和联动。当您使用一个命令同时执行这两项操作时,您只需传递一次:
x86_64-w64-mingw32-g++ 04_key_presses.cpp -m32 \
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w \
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses
我正在尝试遵循 SDL 教程并编译使用 SDL 的 c++ 文件。我在 windows 10,最初使用的是 MinGW。
过了某个时间点,我意识到我的 MinGW 安装出现了与 SDL 无关的问题,所以我改用 MinGW-w64,这解决了非 SDL 问题,但现在当我尝试使用 SDL 编译任何东西时,它找不到 lSDL2 或 lSDL2main。但是,它确实会跳过各种文件,说它们不兼容。
我怀疑这可能是 32 bit/64 位不兼容,但我不确定这是怎么回事,因为即使我明确确保使用 32 位 g++ 编译器,问题仍然存在。作为参考,我输入命令提示符的命令是
x86_64-w64-mingw32-g++ 04_key_presses.cpp
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses
错误信息是
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib\libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2main.a when searching for -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.dll.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib\libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.dll.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\lib/libSDL2.a when searching for -lSDL2
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
您的编译器是x86_64-w64-mingw32-g++
。那是 64 位编译器。
32 位编译器是 i686-w64-mingw32-g++.exe
。 64 位链接
您正在尝试:
x86_64-w64-mingw32-g++ 04_key_presses.cpp \
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w \
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses
跳过不兼容的 32 位 SDL2 库。
64 位编译器可以构建 64 位或 32 位目标,构建
默认为 64 位。要针对 32 位,请为两个编译传递 -m32
和联动。当您使用一个命令同时执行这两项操作时,您只需传递一次:
x86_64-w64-mingw32-g++ 04_key_presses.cpp -m32 \
-IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w \
-Wl,subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o key_presses