编译时SDL2和SDL_image,重新定义和冲突声明

时间:2017-11-23 21:11:25

标签: c++ eclipse g++ sdl-2 sdl-image

我正在尝试使用SDL_image库,因此我可以在使用.png库的窗口中显示SDL2文件。 我的问题是,当我编译代码时,我得到很多关于减速和SDL头文件中的东西的错误。我在Ubuntu LTS 16.04上使用Eclipse

我不完全确定问题是什么以及如何解决这个问题,以便逐步解决这个问题,为什么以及如何让我完全理解它 大

问题的答案在这篇文章的评论中。

这是我的错误

In file included from /usr/include/SDL2/SDL.h:52:0,
                 from /usr/include/SDL2/SDL_image.h:27,
                 from temp.cpp:12:
/usr/include/SDL2/SDL_render.h:116:3: error: conflicting declaration 
‘typedef enum SDL_RendererFlip SDL_RendererFlip’
 } SDL_RendererFlip;
   ^
In file included from /usr/local/include/SDL2/SDL.h:52:0,
                 from temp.cpp:11:
/usr/local/include/SDL2/SDL_render.h:116:3: note: previous declaration 
as 
‘typedef enum SDL_RendererFlip SDL_RendererFlip’
 } SDL_RendererFlip;
   ^
In file included from /usr/include/SDL2/SDL.h:57:0,
                 from /usr/include/SDL2/SDL_image.h:27,
                 from temp.cpp:12:
/usr/include/SDL2/SDL_version.h:51:16: error: redefinition of ‘struct 
SDL_version’
 typedef struct SDL_version

`

这是我的代码

#include <iostream>
#include <string>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <stdio.h>

using namespace std;

int main(int argc, char* argv[])
{
    SDL_Window* window;         
    SDL_Renderer* renderer;     
    SDL_Surface* surface;       
    SDL_Texture* texture;       
    SDL_Init(SDL_INIT_VIDEO);   
    IMG_Init(IMG_INIT_JPG);     


    window = SDL_CreateWindow(  
            "SDL Window",       
            100,                
            600,                
            1200,               
            700,            
            SDL_WINDOW_OPENGL); 

    if (window == NULL)         
    {
        cout << "Could not create window: \n" << SDL_GetError() << 
        endl;   
        return 1;                                               
    }

    renderer = SDL_CreateRenderer (window, -1, 0);          

    surface = IMG_Load("introtext.png");                    
    texture = SDL_CreateTextureFromSurface(renderer, surface);      
    SDL_RenderCopy(renderer, texture, NULL, NULL);              
    SDL_RenderPresent(renderer);

    SDL_Delay(5000);                


    SDL_DestroyTexture(texture);
    SDL_FreeSurface(surface);   
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);      

    IMG_Quit();                     
    SDL_Quit();                     
    return 0;                       
}

0 个答案:

没有答案