与mingw-w64和SDL2链接

时间:2017-09-07 03:44:41

标签: c++ sdl mingw-w64

我正在尝试遵循SDL教程并编译使用SDL的c ++文件。我在Windows 10上,最初使用的是MinGW。

过去某一点我意识到我的MinGW安装有与SDL无关的问题,所以我转而使用MinGW-w64,这清除了非SDL问题,但现在当我尝试用SDL编译任何东西时它可以'找到lSDL2或lSDL2main。但是,它会跳过各种文件,说它们不兼容。

我怀疑它可能是32位/ 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 

1 个答案:

答案 0 :(得分:1)

您的编译器是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