简体   繁体   English

代码:: Blocks,MinGW,libsdl和GNU C ++编译器:未定义对`WinMain @ 16的引用

[英]Code::Blocks, MinGW, libsdl, and GNU C++ compiler: undefined reference to `WinMain@16

I have been trying to compile the most basic SDL application, but no matter what I do I keep getting this error: 我一直在尝试编译最基本的SDL应用程序,但是无论我做什么我都会不断收到此错误:

c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'

I searched for solutions for this, but they all had to do with either Visual C++ or a missing main. 我为此寻找了解决方案,但是它们都与Visual C ++或缺少的main有关。 I am not using Visual C++, and I have defined main. 我没有使用Visual C ++,并且已经定义了main。

Here's my code: 这是我的代码:

#include "SDL/SDL.h"

int main( int argc, char* args[] )
{
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    //Quit SDL
    SDL_Quit();
    return 0;
}

Don't use "Other linker options". 不要使用“其他链接器选项”。 Use the "Link libraries" section. 使用“链接库”部分。 Add the following items. 添加以下项目。

mingw32
SDLmain
SDL

You can put -mwindows in the "Other linker options" section. 您可以将-mwindows放在“其他链接器选项”部分。

In case someone else comes across this, I put -lmingw32 after -lSDLmain and -lSDL which caused this issue for me. 万一别人遇到这个问题,我把-lmingw32 -lSDLmain和-lSDL造成这个问题对我之后 Putting -lmingw32 first fixed it. 首先将-lmingw32固定。

I encountered the same error in a project of mine that I want to compile both on linux and windows. 我在我的项目中遇到了要在linux和Windows上编译的相同错误。 I use a makefile to compile the project. 我使用makefile来编译项目。 A solution that has worked for me, although I admit it is a bit of a hack is adding this to main.cpp (wherever your main function would be) 一个对我有用的解决方案,尽管我承认这有点麻烦,但仍将其添加到main.cpp中(无论您的主要功能在哪里)

extern "C" {

    int WinMain(int argc, char** argv)
    {
        return main(argc, argv);
    }
}

This makes the linker find WinMain and use it as the entry point in the program. 这使链接器找到WinMain并将其用作程序中的入口点。 I can also hope that this solution doesn't break linux compilability, hopefully it will be considered just an unused function. 我也可以希望该解决方案不会破坏linux的可编译性,希望它将被视为未使用的函数。

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

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