2

I am trying to use the SDL_image library so I can display a .png file in a window made using SDL2 library. My problem is when ever I compile the code I get a lot of errors of about deceleration and stuff in the SDL header files. I'm using Eclipse on Ubuntu LTS 16.04

I am not entirely sure of what the problem is and how I can solve this so a step by step of what, why and how so I can fully understand it would be great

Answer to question is in comments of this post.

Here are my Errors

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

`

Here is my code

#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;                       
}
Bananas88
  • 23
  • 8
  • 1
    Please don't link to an image of errors. Put the errors directly *in* the question as *text*. – Jesper Juhl Nov 23 '17 at 21:16
  • 2
    Updated post now – Bananas88 Nov 23 '17 at 21:23
  • What versions of SDL and SDL_Image are you using? And how are they bundled? I've used it only once for a small demo app and I have them as 2 separate libraries. – Guy Kogus Nov 23 '17 at 21:34
  • i got them bothing using `sudo apt-get install libsdl-dev` and what ever the one for getting SDL_image I forget. I linked them both in the project settings. so I assume I'm using both the latest versions available. I am not sure what you mean by how they are bundled. – Bananas88 Nov 23 '17 at 21:38
  • 1
    It appears you have headers in both `/usr/include/SDL2` (likely to be installed by package manager) and `/usr/local/include/SDL2` (likely to be installed by something else), and these two are not the same and conflicting. On deb-based systems you can check which package file belongs to with `dpkg -S /usr/local/include/SDL2/SDL.h` (probably none). – keltar Nov 24 '17 at 08:38
  • can I just delete the header files at `/usr/local/include/SDL2/SDL.h`? or is there something else I need to do to solve this problem? – Bananas88 Nov 24 '17 at 09:42
  • @Bananas88 if you don't remember putting it here and it doesn't belong to any package, I suppose you should delete this entire directory, not just SDL.h (or move it somewhere else until you sure) – keltar Nov 24 '17 at 11:25
  • Well I just renamed the folder and that has seemed to fix the problem for now. but going to leave it there just in case something does use it I can just change the name back – Bananas88 Nov 24 '17 at 12:21

0 Answers0