我需要 SDL 的 main() 函数吗? [英] Do I need SDL's main() function?

查看:49
本文介绍了我需要 SDL 的 main() 函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑从我自己的私人语言中使用 SDL2.他们可以与诸如 SDL2.dll 之类的动态库进行通信,因此这可能是可行的.但首先我需要使用 C 来尝试一下.

I'm looking at possibly using SDL2 from my own private languages. They can talk to dynamic libraries such as SDL2.dll so it might be feasible. But first I need to try it out using C.

但是,hello-world 风格的教程是难以捉摸的(它们适用于错误的 SDL 版本,或者它们使用的是 C++ 或其他).然而,最后我组合了一个最小程序(只需 #include "sdl.h" 和 main(){} 将显示问题),我无法链接,因为我没有 main() 或 WinMain().

But, a hello-world style of tutorial was elusive (they're for the wrong version of SDL, or they're in C++ or whatever). Finally however I put together a minimum program (just #include "sdl.h" and main(){} will show the problem), and I can't link because I don't have main() or WinMain().

我知道 SDL.h 或其他一些头文件重新定义了我的main",因为它想使用自己的 main() 例程.这大概存在于一些静态链接的 SDL 库中,因为它不能在 SDL2.dll 中.我没有那个库,也看不到获得它的任何意义,因为我无法在我自己的语言中使用它(它也将是特定于实现的,甚至作为源代码,在这种情况下忘记它!).

I understand that SDL.h or some other header redefines my 'main', as it wants to use its own main() routine. That presumably lives in some statically linked library of SDL, as it can't be inside SDL2.dll. I don't have that library and can't see any point in getting it as I won't be able to use it in my own language (also it will be implementation specific or even come as source code, in which case forget it!).

通过添加#undef main",我设法让一个基本的测试程序运行起来.

I managed to get a basic test program working by adding '#undef main'.

但是,我的问题是,SDL 的 main() 中是否有我需要的或将来可能会影响我的重要内容?或者我可以离开它吗?(为什么 SDL 不只依赖一些 SDL_init() 例程让我从 main() 调用?)

My question is, however, is there anything essential in SDL's main() that I will need, or that is likely to bite me in the future? Or can I get away without it? (And why doesn't SDL just depend on some SDL_init() routine for me to call from my main()?)

(我在 SDL 论坛注册并询问此事,但显然他们不允许我发帖,因为我没有正确的权限.那么注册的意义何在?!)

(I registered with SDL forums to ask about this, but apparently they don't allow me to post, as I don't have the right privileges. So what was the point of registering?!)

推荐答案

在包含 SDL.h<之前,您应该 #define SDL_MAIN_HANDLED 而不是 #undef main/code>(或通过编译器标志定义它).

Instead of #undef main you should #define SDL_MAIN_HANDLED before including SDL.h (or define it via compiler flag).

如果您实现自定义主函数,您至少应该调用 SDL_SetMainReady.对于某些平台,SDL 会执行额外的操作,例如设置特定的异常处理程序、将参数转换为 UTF8 或完全不同的操作(例如,对于 android,它实际上不是一个 main 函数而是 JNI 函数).

If you implement custom main function you should at least call SDL_SetMainReady. For some platforms, SDL performs additional operations, like setting specific exception handlers, converting arguments to UTF8, or something completely different (e.g. for android it is not really a main but JNI function).

SDL2main 库中定义的SDL 入口点,并没有真正理解你做了什么没有它"(除了手动删除它).您可以随时从 libsdl.org 下载存档或自行构建.

SDL's entry point defined in SDL2main library, don't really understand what you did to 'don't have it' (aside from manually deleting it). You can always download archive from libsdl.org or build it yourself.

这篇关于我需要 SDL 的 main() 函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆