简体   繁体   English

如何从Linux for Windows交叉编译SDL 2

[英]How to cross-compile with SDL 2 from Linux for Windows

I tried to compile a simple C++ program that uses SDL 2 with the mingw-w64-g++ compiler on my Arch Linux (64bits). 我尝试编译一个简单的C ++程序,它在我的Arch Linux(64位)上使用SDL 2和mingw-w64-g ++编译器。

For this I downloaded SDL2-devel-2.0.4-mingw.tar.gz from here 为此,我从这里下载了SDL2-devel-2.0.4-mingw.tar.gz

prog.cpp: prog.cpp:

#include <SDL.h>

int main ()
{
    SDL_Init (SDL_INIT_VIDEO);

    SDL_Window *sdlWnd = SDL_CreateWindow ("Test", SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED, 800, 600, 0);

    SDL_Event event;
    bool running = true;

    while (running) {
        while (SDL_PollEvent (&event)) {
            if (event.type == SDL_QUIT) {
                running = false;
                break;
            }
        }
    }

    return 0;
}

Makefile: Makefile文件:

GPP = x86_64-w64-mingw32-g++
prog.exe: prog.o
    $(GPP) -o prog.exe prog.o -LSDL2-2.0.4/lib/x64 -lSDL2main -lSDL2
prog.o: prog.cpp
    $(GPP) -o prog.o -c -ISDL2-2.0.4/include prog.cpp

Now making gives the error: 现在制作错误:

x86_64-w64-mingw32-g++ -o prog.exe prog.o -LSDL2-2.0.4/lib/x64 -lSDL2main -lSDL2
Warning: corrupt .drectve at end of def file
SDL2-2.0.4/lib/x64/SDL2main.lib(./x64/Release/SDL_windows_main.obj):(.text[main]+0x1c): undefined reference to `SDL_main'

Why undefined reference to `SDL_main' ? 为什么未定义引用`SDL_main'? Although I specified -lSDL2main ? 虽然我指定了-lSDL2main?

What did I do wrong? 我做错了什么? :( :(

Okay, it was because of the main functions signature, that has to be declared as: 好的,这是因为主要功能签名,必须声明为:

int main(int argc, char *argv[])

according to the official SDL FAQ : 根据官方SDL常见问题解答

Make sure that you are declaring main() as: 确保将main()声明为:

 #include "SDL.h" int main(int argc, char *argv[]) 

You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code. 即使您正在创建Windows应用程序,也应该使用main()而不是WinMain(),因为SDL提供了一个版本的WinMain(),它在调用主代码之前执行一些SDL初始化。 If for some reason you need to use WinMain(), take a look at the SDL source code in src/main/win32/SDL_main.c to see what kind of initialization you need to do in your WinMain() function so that SDL works properly. 如果由于某种原因你需要使用WinMain(),请查看src / main / win32 / SDL_main.c中的SDL源代码,看看你需要在WinMain()函数中做什么样的初始化,以便SDL工作正常。

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

相关问题 使用 VS Code 在 Linux 上使用 MinGW 交叉编译适用于 Windows 的 SDL 程序? - Cross-compile SDL programs for Windows with MinGW on Linux in VS Code? 有没有一种从 Linux 安装交叉编译 SFML 的好方法 - Is there a good way to cross-compile SFML for windows from a Linux install Qt6 on Linux for Windows如何交叉编译? - How to cross-compile Qt6 on Linux for Windows? 在Linux上使用GCC交叉编译Windows的Qt应用程序 - Use GCC on Linux to cross-compile Qt apps for Windows Windows编译.o但不编译.a的Boost for GCC ARM(Linux)的交叉编译。 - Cross-Compile of Boost for GCC ARM (Linux) from Windows building .o but not .a 是否可以从 Linux 为 Windows XP 交叉编译 C++ 应用程序? - Is it possible to cross-compile C++ applications from Linux for Windows XP? 如何在 Windows 上使用 Eclipse 交叉编译树莓派 - How to Cross-Compile Raspberry Pi using Eclipse on Windows 如何从 Linux 编译到 Windows 的 SDL2 应用程序? - How to compile to SDL2 application to Windows from Linux? 交叉编译程序找不到SDL2标头 - Cross-compile program can't find SDL2 headers 如何将我正在交叉编译的程序的ubuntu上的GLEW交叉编译到Windows? - How can I cross-compile GLEW on ubuntu to windows for a program I am cross-compiling?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM