未定义引用WinMain

未定义引用WinMain

本文介绍了未定义引用WinMain @ 16 C ++,SDL-2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误未定义的引用WinMain @ 16 。为了节省空间, 。目前,除了创建一个窗口,填充它的绿色,然后在角落绘制一个框,所有的同时跟踪我的鼠标的位置通过控制台不应该做太多。

I've been getting the error undefined reference to WinMain@16. To save space, here's a link to all the files currently in the project. At present, it shouldn't do much other than create a window, fill it in green and then draw a box in the corner, all the while tracking my mouse's position through the console. However, it won't build and I'm given the aforementioned error.

我的链接器库是:


  • glew32s

  • libSDL2main

  • mingw32

  • libSDL2

  • opengl32

  • glew32

  • glew32s
  • libSDL2main
  • mingw32
  • libSDL2
  • opengl32
  • glew32

我使用Codeblocks 13.12 with g ++ following C ++ 11 ISO C ++语言标准。我的电脑在使用Windows 10的情况下是相关的。

I am using Codeblocks 13.12 with g++ following the C++11 ISO C++ language standard. My PC is using windows 10 in case that's relevant.

我花了相当多的时间试图找到一个解决方案,似乎每个人都有一个完全不同的,远没有一个为我工作。几个示例包括:

I've spent quite a while trying to find a solution and it seems everyone has an entirely different one, and so far none of them have worked for me. A few examples include:


  • 按照。它给了我错误 -lSDL2_image

  • 如果一些打字错误没有注意到的原因,完全从头开始项目。

  • 函数更改为 WinMain

  • 添加了 Windows.h 标题。这没有什么明显的。

  • 我的喜欢图书馆的各种所谓正确的订单。

  • Adding SDL2_image to my link libraries in accordance with this similar question. It gave me the error -lSDL2_image.
  • Starting the project entirely from scratch in case some typo I failed to notice was the cause. (I got exactly the same error).
  • Changing my main function to WinMain. I got the same error message.
  • Adding a Windows.h header. This did nothing noticeable.
  • Various alleged "right orders" for my liker libraries. None of those have seemed to help thus far.

我还应该指出,用户提供的答案,Cheers和hth。 - Alf,可能是我要找的,但在所有诚实我不能完全理解我应该根据它做什么。

I should also point out that the answer provide by the user, Cheers and hth. - Alf, here might be what I'm looking for, but in all honesty I can't fully understand what I'm supposed to do in based on it.

如果有任何相关信息,我忘了包括,请告诉我和我尽快这样做。提前感谢。

If there's any relevant information that I forgot to include, please tell me and I'll do so as soon as possible. Thanks in advance.

推荐答案

我想你想要

#define SDL_MAIN_HANDLED

>

in your main file, BEFORE the line

#include <SDL2/SDL.h>

说明:

在SDL / SDL2 ,为了努力使某些类型的应用程序的跨平台开发更简单,SDL为您的应用程序创建了一个自定义入口点。也就是说, int main()不是 real main。发生什么, main 被定义为SDL头中的一个宏,这将导致你的主要被重命名为 SDL_main 或类似物。然后,在SDL_main库中定义了一个不同的 main ,它将是应用程序的真实 main main 只是以适合于平台的任何方式获取命令行参数,并调用 main 已重命名为 SDL_main )。

In SDL / SDL2, in an effort to try to make cross-platform development of certain kinds of applications simpler, SDL creates a custom "entry-point" to your application. That is, your int main() is not the real main. What happens is, main is defined as a macro in the SDL header and this causes your main to be renamed to SDL_main or similar. Then, in the "SDL_main" library a different main is defined which will be the real main of your application. This main just fetches the command-line arguments in whatever way is appropriate for the platform, and calls your main (which was renamed SDL_main).

在Windows上,对于您的应用程序是否作为控制台启动

On windows, there are also some differences regarding whether your application is started as a console program vs. as a gui program, iiuc.

有时你希望SDL为你做这些事情,但是如果你正在开发一个传统的控制台程序, t。所以你传递SDL这个 SDL_MAIN_HANDLED define为了防止做所有这些东西。

Sometimes you want SDL to do these things for you, but if you are developing a traditional console program, usually you don't. So you pass SDL this SDL_MAIN_HANDLED define in order to prevent from doing all this stuff.

#undef main 方法也可以工作,但它不是那么好,因为这样,你告诉SDL发生了什么,用另一种方法,SDL认为所有的东西将是

The #undef main approach will work also, but it's not quite as good because this way, you tell SDL what is going on, with the other method, SDL thinks that all it's stuff is going to be used and in fact you crudely disable it with #undef later.

如果你想查看各种各样的详细信息,你可以使用 #undef 宏/平台检查,可以查看 SDL_main.h 头。如果你想知道SDL主系统的好处,你可以看一下SDL文档。

If you want to see details of the various macros / platform checks, you can look in the SDL_main.h header. If you want to know what the benefits of the SDL main system are, you can look at SDL documentation.

这篇关于未定义引用WinMain @ 16 C ++,SDL-2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 21:36