Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SDL C++;:SDL错误的多重定义 我在遵循C++中的SDL教程,在编译其中的一些文件时,遇到了一个错误,这里定义了SDL的多重定义。 我使用DEV C++。< /P>_C++_Sdl_Multiple Definition Error - Fatal编程技术网

SDL C++;:SDL错误的多重定义 我在遵循C++中的SDL教程,在编译其中的一些文件时,遇到了一个错误,这里定义了SDL的多重定义。 我使用DEV C++。< /P>

SDL C++;:SDL错误的多重定义 我在遵循C++中的SDL教程,在编译其中的一些文件时,遇到了一个错误,这里定义了SDL的多重定义。 我使用DEV C++。< /P>,c++,sdl,multiple-definition-error,C++,Sdl,Multiple Definition Error,我用谷歌搜索了我的错误的解决方案,但它似乎从来没有解决我的问题 main.cpp: //The headers #include "SDL/SDL.h" #include <string> //The attributes of the screen const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; //The surfaces that will be

我用谷歌搜索了我的错误的解决方案,但它似乎从来没有解决我的问题

main.cpp:

//The headers
#include "SDL/SDL.h"
#include <string>

//The attributes of the screen
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The surfaces that will be used
SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;

SDL_Surface *load_image( std::string filename )
{
    //Temporary storage for the image that's loaded
    SDL_Surface* loadedImage = NULL;

    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;

    //Load the image
    loadedImage = SDL_LoadBMP( filename.c_str() );

    //If nothing went wrong in loading the image
    if( loadedImage != NULL )
    {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat( loadedImage );

        //Free the old image
        SDL_FreeSurface( loadedImage );
    }

    //Return the optimized image
    return optimizedImage;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
    //Make a temporary rectangle to hold the offsets
    SDL_Rect offset;

    //Give the offsets to the rectangle
    offset.x = x;
    offset.y = y;

    //Blit the surface
    SDL_BlitSurface( source, NULL, destination, &offset );
}

int main( int argc, char* args[] )
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return 1;
    }

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //If there was an error in setting up the screen
    if( screen == NULL )
    {
        return 1;
    }

    //Set the window caption
    SDL_WM_SetCaption( "Hello World", NULL );

    //Load the images
    message = load_image( "hello.bmp" );
    background = load_image( "background.bmp" );

    //Apply the background to the screen
    apply_surface( 0, 0, background, screen );
    apply_surface( 320, 0, background, screen );
    apply_surface( 0, 240, background, screen );
    apply_surface( 320, 240, background, screen );

    //Apply the message to the screen
    apply_surface( 180, 140, message, screen );

    //Update the screen
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;
    }

    //Wait 2 seconds
    SDL_Delay( 2000 );

    //Free the surfaces
    SDL_FreeSurface( message );
    SDL_FreeSurface( background );

    //Quit SDL
    SDL_Quit();

    return 0;
}
//标题
#包括“SDL/SDL.h”
#包括
//屏幕的属性
屏幕宽度=640;
屏幕上的常数=480;
屏幕常数(BPP=32);
//将要使用的曲面
SDL_表面*信息=NULL;
SDL_表面*背景=空;
SDL_表面*屏幕=空;
SDL_表面*加载_图像(标准::字符串文件名)
{
//已加载映像的临时存储
SDL_表面*LoadeImage=NULL;
//将使用的优化图像
SDL_曲面*optimizedImage=NULL;
//加载图像
loadedImage=SDL_LoadBMP(filename.c_str());
//如果加载图像时没有出错
如果(LoadeImage!=NULL)
{
//创建一个优化的图像
optimizedImage=SDL_显示格式(LoadeImage);
//释放旧图像
SDL_自由曲面(加载图像);
}
//返回优化后的图像
返回优化年龄;
}
void apply_surface(int x,int y,SDL_surface*源,SDL_surface*目标)
{
//制作一个临时矩形以容纳偏移
垂直偏移量;
//给出矩形的偏移量
偏移量x=x;
偏移量y=y;
//浮出水面
SDL_BlitSurface(源、空、目标和偏移);
}
int main(int argc,char*args[]
{
//初始化所有SDL子系统
if(SDL_Init(SDL_Init_EVERYTHING)=-1)
{
返回1;
}
//设置屏幕
屏幕=SDL_设置视频模式(屏幕宽度、屏幕高度、屏幕BPP、SDL_表面);
//如果设置屏幕时出错
如果(屏幕==NULL)
{
返回1;
}
//设置窗口标题
SDL_WM_SetCaption(“你好,世界”,空);
//加载图像
message=load_image(“hello.bmp”);
背景=加载_图像(“background.bmp”);
//将背景应用于屏幕
应用_表面(0,0,背景,屏幕);
应用_表面(320,0,背景,屏幕);
应用_表面(0,240,背景,屏幕);
应用于表面(320、240、背景、屏幕);
//将消息应用到屏幕上
应用_表面(180、140、信息、屏幕);
//更新屏幕
如果(SDL_翻转(屏幕)=-1)
{
返回1;
}
//等2秒钟
SDL_延迟(2000年);
//释放表面
SDL_自由曲面(消息);
SDL_自由曲面(背景);
//退出SDL
SDL_退出();
返回0;
}
错误:


即使没有行号,我也无法找出特定代码的实际问题所在。谢谢

您确定正确设置了所需的Include和LIB吗?我建议您创建一个新项目,并使用最基本的功能测试它—init SDL、创建窗口、清理和退出。一旦你知道这是可行的,你就可以把你的代码放回去了。@Zammalad谢谢我犯了一个错误,我在一个项目中添加了两个文件,将文件分开,现在它工作正常了。谢谢