使用代码块中的SDL_ShowSimpleMessageBox混淆错误,内存不足和未定义引用

问题描述 投票:1回答:1

所以我从代码块开始,并在线跟踪教程,我做了一个有一个文件的空项目。

#include <SDL.h>
#include <stdio.h>


//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main( int argc, char* args[] )
{
    //The window we'll be rendering to
    SDL_Window* window = NULL;

    //The surface contained by the window
    SDL_Surface* screenSurface = NULL;

    //Initialize SDL
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
    }
    else
    {
        //Create window
        window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
        if( window == NULL )
        {
            printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
        }
        else
        {
            //Get window surface
            screenSurface = SDL_GetWindowSurface( window );

            //Fill the surface white
            SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );

            //Update the surface
            SDL_UpdateWindowSurface( window );

            //Wait two seconds
            SDL_Delay( 2000 );
        }
    }

    //Destroy window
    SDL_DestroyWindow( window );

    //Quit SDL subsystems
    SDL_Quit();

    return 0;
}

链接器设置:

-lmingw32 -lSDL2main -lSDL2

我得到这个错误,

||=== Build: Debug in Yeet (compiler: GNU GCC Compiler) ===|
D:\Coding\addons\lib\x86\SDL2main.lib(Win32\Release\SDL_windows_main.obj):(.text[_OutOfMemory]+0xf)||undefined reference to `SDL_ShowSimpleMessageBox'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

我不确定这是一个内存错误,还是一个未定义的引用错误,如果它是一个内存错误我不知道为什么因为其他更大的程序有足够的内存,并且未定义的引用错误的一段代码似乎不在我的代码中...任何帮助将不胜感激。 :)

c++ sdl codeblocks sdl-2
1个回答
0
投票

所以是的我使用了错误的库,所以如果其他人遇到问题,请确保您正在为IDE下载正确的文件。谢谢HolyBlackCat :)

© www.soinside.com 2019 - 2024. All rights reserved.