简体   繁体   English

如何从 Linux 编译到 Windows 的 SDL2 应用程序?

[英]How to compile to SDL2 application to Windows from Linux?

So recently I downloaded the Linux Subsystem on Windows 10, with Ubuntu.所以最近我在 Windows 10 上下载了 Linux 子系统,带有 Ubuntu。

I can compile an SDL2 app to Linux with the g++ command but whenever I try doing it with i686-w64-mingw32-g++ this command, I get an error saying main.cpp:5:9: fatal error: SDL2/SDL.h: No such file or directory .我可以使用g++命令将 SDL2 应用程序编译为 Linux 但是每当我尝试使用i686-w64-mingw32-g++这个命令执行它时,我都会收到一条错误main.cpp:5:9: fatal error: SDL2/SDL.h: No such file or directory

The command I'm using is i686-w64-mingw32-g++ main.cpp -w -lSDL2 -o main.exe .我使用的命令是i686-w64-mingw32-g++ main.cpp -w -lSDL2 -o main.exe

https://imgur.com/a/uqcGCoJ https://imgur.com/a/uqcGCoJ

Anyone knows how to fix this?任何人都知道如何解决这个问题? :( :(

[EDIT] [编辑]

So now I've tried specifying the directory of the necesary files with this command: g++ main.cpp -I/usr/include/SDL -L/usr/lib/x86_64-linux-gnu -w -Wall -Wextra -std=c++17 -lSDL2 -o main所以现在我尝试使用以下命令指定必要文件的目录: g++ main.cpp -I/usr/include/SDL -L/usr/lib/x86_64-linux-gnu -w -Wall -Wextra -std=c++17 -lSDL2 -o main

which worked but when I use it with mingw it doesn't i686-w64-mingw32-g++ main.cpp -I/usr/include/SDL -L/usr/lib/x86_64-linux-gnu -w -Wall -Wextra -std=c++17 -lSDL2 -o main这有效,但是当我将它与 mingw 一起使用时,它不会i686-w64-mingw32-g++ main.cpp -I/usr/include/SDL -L/usr/lib/x86_64-linux-gnu -w -Wall -Wextra -std=c++17 -lSDL2 -o main

https://imgur.com/a/sF6CpcP https://imgur.com/a/sF6CpcP

You need to include the path to SDL's include directory on the command line. 您需要在命令行上包含SDL的include目录的路径。 However, you need to include the path to the downloaded SDL for mingw32, not /usr/include/SDL2. 但是,您需要包括mingw32的已下载 SDL的路径,而不是/ usr / include / SDL2。 The difference is the headers in /usr/include/SDL2 are for Linux and libs in /usr/lib are also for Linux, but you need to link to the Windows libraries. 区别在于/ usr / include / SDL2中的标头适用于Linux,/ usr / lib中的libs也适用于Linux,但是您需要链接到Windows库。

What I usually do is download the development libraries for Mingw32 and put them directly into my project directory. 我通常要做的是下载Mingw32的开发库,并将它们直接放入我的项目目录中。 Then all you need to do is add -ISDL2-2.0.8/i686-w64-mingw32/include -LSDL2-2.0.8/i686-w64-mingw32/lib to your command line and it will be able to find the headers and libraries it needs. 然后,您需要做的就是在命令行中添加-ISDL2-2.0.8 / i686-w64-mingw32 / include -LSDL2-2.0.8 / i686-w64-mingw32 / lib ,这样便可以找到标头和它需要的库。 Finally, make sure you copy SDL2-2.0.8/i686-w64-mingw32/bin/SDL2.dll to your executable directory in the Makefile. 最后,确保将SDL2-2.0.8 / i686-w64-mingw32 / bin / SDL2.dll复制到Makefile中的可执行目录中。

Also, remember to link SDLmain as well. 另外,请记住也要链接SDLmain。 It handles creating a WinMain for you and all that, and then calls your main function. 它负责为您以及所有这些创建WinMain,然后调用您的main函数。

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

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