Thread: SDL2 Compilation Error in C

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    2

    Exclamation SDL2 Compilation Error in C

    Hey guys,
    So I'm trying to get SDL2 set up on my Ubuntu machine (18.04).
    I've written the following code so far
    Code:
    #include <stdio.h>
     #include <SDL2/SDL.h>
      #include <stdlib.h>
    
    #define SCREEN_WIDTH 640
      #define SCREEN_HEIGHT 480
    
    int main()
      {
    SDL_WINDOW* window;
    
     if(SDL_Init(SDL_INIT_VIDEO)!= 0){
     fprintf(stderr, "Could not initialize SDL Video: %s\n", SDL_GetError());
     }
    
     window = SDL_CreateWindow("hello", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
    
     if(window == NULL) {
     fprintf(stderr, "Could not create window: %s\n", SDL_GetError());
     }
     return 0;
     }
    Tried compiling using "gcc -o game game.c `sdl2-config --cflags --libs`" as well as with "gcc -o -lSDL2 game game.c". Each time it shows the same error:

    error: unknown type name ‘SDL_WINDOW’; did you mean ‘SDL_LINE’?
    SDL_WINDOW* window;

    Please help! I've tried uninstalling and reinstalling. Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    C is case sensitive.

    The type is SDL_Window
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2020
    Posts
    2
    Oh my god, thank you. Just one of those days, I'm braindead :/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL2 Codeblocks error
    By russiancircles in forum Game Programming
    Replies: 2
    Last Post: 05-08-2014, 06:08 AM
  2. Compilation Error
    By samuraiexx in forum C Programming
    Replies: 4
    Last Post: 09-21-2011, 12:19 AM
  3. Compilation Error
    By sunk22 in forum C Programming
    Replies: 9
    Last Post: 05-25-2011, 12:00 PM
  4. error: was not declared in this scope compilation error
    By i_r_tomash in forum C Programming
    Replies: 2
    Last Post: 05-27-2010, 07:44 AM
  5. help about compilation error
    By netwizio in forum Linux Programming
    Replies: 2
    Last Post: 01-16-2004, 06:22 PM

Tags for this Thread