Problems compiling this SDL app

This is a discussion on Problems compiling this SDL app within the C++ Programming forums, part of the General Programming Boards category; (from a thread that got nuked) I've just gotten SDL to work properly for a change, and was able to ...

  1. #1
    Registered User Rider's Avatar
    Join Date
    Nov 2005
    Posts
    28

    Exclamation Problems compiling this SDL app

    (from a thread that got nuked)

    I've just gotten SDL to work properly for a change, and was able to compile a basic SDL app with it.

    Now I'm trying to get the hang of SDL itself, but this latest attempt at an SDL app doesn't want to compile. It gives me the following error:

    Code:
    SDL/lib/libSDLmain.a(SDL_win32_main.o.b)(.text+0x362): In function `console_main
    ':
    /home/hercules/public_cvs/SDL/src/main/win32/SDL_win32_main.c:217: undefined ref
    erence to `SDL_main'
    And here's the program code:

    Code:
    //The headers
    #include "SDL/SDL.h"
    #include <string>
    #include <cstdlib>
    #include <iostream>
    
    //The attributes of the screen
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;
    const int SCREEN_BPP = 32;
    
    SDL_Surface *screen; //This pointer will reference the backbuffer
    SDL_Surface *image;
    SDL_Surface *temp;
    
    int InitVideo(Uint32 flags = SDL_DOUBLEBUF | SDL_FULLSCREEN) {
      // Load SDL
      if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
        return false;
      }
      atexit(SDL_Quit); // Clean it up nicely :)
    
      // fullscreen can be toggled at run time :) any you might want to change the flags with params?
      //set the main screen to SCREEN_WIDTHxSCREEN_HEIGHT with a colour depth of 16:
      screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_DOUBLEBUF | SDL_FULLSCREEN);
      if (screen == NULL) {
        fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
        return false;
      }
      return true;
    }
    
    
    int main()
    {
    
    InitVideo();
    
    temp = SDL_LoadBMP("hello_world.bmp");
    if (temp == NULL) {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }
        
    image = SDL_DisplayFormat(temp);
    SDL_FreeSurface(temp);
    
    SDL_Rect src, dest;
     
    src.x = 0;
    src.y = 0;
    src.w = image->w;
    src.h = image->h;
     
    dest.x = 100;
    dest.y = 100;
    dest.w = image->w;
    dest.h = image->h;
     
    SDL_BlitSurface(image, &src, screen, &dest);
    
    SDL_Flip(screen);
    SDL_Delay(2500);
    
    SDL_FreeSurface(image);
    
    return 0;
    }

    Any help is again appreciated

  2. #2
    mog
    mog is offline
    Sasquatch mog's Avatar
    Join Date
    Dec 2006
    Location
    Caves of Narshe
    Posts
    16
    Are you compiling / linking against SDL lib?

    Code:
    // ex.
    gcc app.c -o app -lsdl

  3. #3
    Registered User Rider's Avatar
    Join Date
    Nov 2005
    Posts
    28
    Yes I am, for further reference, here is what my compiling batchfile says:
    Code:
    gcc -c SDLTest.cpp 
    g++ -o SDLTest SDLTest.o -I SDL/include -L SDL/lib -lmingw32 -lSDLmain -lSDL -mwindows

  4. #4
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    This is a problem regarding how you declare main(), you need to declare it:

    int main(int argc, char ** argv)

    or it won't compile properly with SDL.

    Effectively the "real" main() is inside SDL. Your code's main() is renamed (via macro) to SDL_main() and then called from within the "real" main(). Because function calls require exact parameter types, you need the int and char** parameters.
    Last edited by Cat; 03-27-2007 at 01:25 PM.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems With SDL keysym
    By IdioticCreation in forum C++ Programming
    Replies: 0
    Last Post: 12-20-2007, 06:54 PM
  2. Singleton problems
    By techrolla in forum C++ Programming
    Replies: 16
    Last Post: 01-02-2005, 04:05 PM
  3. SDL and MinGW Studio
    By Vicious in forum Tech Board
    Replies: 0
    Last Post: 07-30-2004, 10:59 PM
  4. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 11:28 AM
  5. Problems with my RPG app
    By valar_king in forum Game Programming
    Replies: 1
    Last Post: 12-15-2001, 08:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21