使用SDL库时的链接器错误:_main已在main.obj中定义 [英] Linker Error when using the SDL Library: _main already defined in main.obj

查看:167
本文介绍了使用SDL库时的链接器错误:_main已在main.obj中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经知道为什么会发生此错误,在SDL_main.h文件中创建了一个"main"宏,这将导致您实际的main函数出现问题.

So I already know why this error happens, inside the SDL_main.h file a 'main' macro is being created, which will cause problems with your actual main function.

只是所有明显的解决方法似乎都没有帮助我.我已经尝试过:

It's just that none of the obvious workarounds seem to be helping me. I have tried:

  1. 使用(int argc,char * argv [])定义我的主要功能.

  1. Defining my main function with (int argc, char* argv[]).

使用C链接对其进行了尝试,如SDL_main.h中的注释所示:

Tried it with C linkage like the comments in SDL_main.h suggest:

*  The application's main() function must be called with C linkage,
*  and should be declared like this:
*  \code
*  #ifdef __cplusplus
*  extern "C"
*  #endif
*  int main(int argc, char *argv[])
*  {
*  }
*  \endcode

  • 尝试不确定主线.

  • Tried undefining main.

    我还可以尝试使用其他技巧来使主功能再次正常工作吗?

    Are there any other tricks I can try in order to get the main function working normally again?

    推荐答案

    也可以在main.cpp文件顶部尝试此操作:

    Try also this at the top of your main.cpp file:

    #define SDL_MAIN_HANDLED
    

    这应该导致SDL跳过所有的main废话.

    That is supposed to cause SDL to skip all of its main nonsense.

    请注意,在包含SDL之前,需要先进行以下操作:

    Note that it needs to happen before you include SDL:

    #define SDL_MAIN_HANDLED
    #include "SDL2/SDL.h"
    

    这篇关于使用SDL库时的链接器错误:_main已在main.obj中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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