Why Error?

Started by
10 comments, last by HOTSHOT 19 years, 4 months ago
Hiya all I got all the image, SDL.dll, resource files and everythings on same folder and it should work... my questions is why doesnt work? I show the were the error when I run the program. I using Bloodshed Version 5. I would be delight if anyone can help me.... cheer

// "Graphics with SDL" turorial series Lesson 2
// by Marius Andra (http;//cone3d.gamedev.net/)
//
// NOTE: don't be alarmed if running this from
// Dev-C++ turns up a black screen. Compile it and then
// run it from the sources folder.

#include <stdio.h>
#include <stdlib.h>

#include <SDL/SDL.h>

SDL_Surface *back;  <<< ERROR
SDL_Surface *image;
SDL_Surface *screen;

int xpos=0,ypos=0;

int InitImages()
{
  back = SDL_LoadBMP("bg.bmp");
  image = SDL_LoadBMP("image.bmp");
  return 0;
}

void DrawIMG(SDL_Surface *img, int x, int y)
{
  SDL_Rect dest;
  dest.x = x;
  dest.y = y;
  SDL_BlitSurface(img, NULL, screen, &dest);
}

void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2)
{
  SDL_Rect dest;
  dest.x = x;
  dest.y = y;
  SDL_Rect dest2;
  dest2.x = x2;
  dest2.y = y2;
  dest2.w = w;
  dest2.h = h;
  SDL_BlitSurface(img, &dest2, screen, &dest);
}

void DrawBG()
{
  DrawIMG(back, 0, 0);
}

void DrawScene()
{
  DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);
  DrawIMG(image, xpos, ypos);

  SDL_Flip(screen);
}

int main(int argc, char *argv[])
{
  Uint8* keys;

  if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
  {
    printf("Unable to init SDL: %s\n", SDL_GetError());
    exit(1);
  }
  atexit(SDL_Quit);

  screen=SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
  if ( screen == NULL )
  {
    printf("Unable to set 640x480 video: %s\n", SDL_GetError());
    exit(1);
  }

  InitImages();
  DrawBG();

  int done=0;

  while(done == 0)
  {
    SDL_Event event;

    while ( SDL_PollEvent(&event) )
    {
      if ( event.type == SDL_QUIT )  {  done = 1;  }

      if ( event.type == SDL_KEYDOWN )
      {
        if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
      }
    }
    keys = SDL_GetKeyState(NULL);
    if ( keys[SDLK_UP] ) { ypos -= 1; }
    if ( keys[SDLK_DOWN] ) { ypos += 1; }
    if ( keys[SDLK_LEFT] ) { xpos -= 1; }
    if ( keys[SDLK_RIGHT] ) { xpos += 1; }

    DrawScene();
  }

  return 0;
}

[edit: use source tags for large blocks of code, please. -superpig] [Edited by - superpig on November 27, 2004 10:53:39 AM]
Advertisement
What exactly is the error?
What's the error?

EDIT:Beaten to it
You probably need to include the lib for sdl.dll into your linker options. It sounds like you have it in the folder, but have not actually connected it properly. Should be under project options->parameters or something of the like (that is from DevC++).
--Eric BurnettI know I have mnemophobia, but I can't remember what it is.
you don't link to SDL.dll in the options. you link to libSDL.a and libSDLmain.a.

to do this, go to project settings and select the parameters tab. there's a text list that has a label of "linker". in this box, you add "-lSDL -lSDLmain" (without the quotes). also make sure "-lmingw32" (also without the quotes) is in the same text list.

As stated above, it would help if you included an error message in your post. It would be helpful to us in helping you solve your problem.
Hiya all

I have update my Bloodshed C++ version 5 and now I just small problem

When I run the Lesson 2 program and I get the error here

[Linker error] undefined reference to `SDL_RWFromFile'
[Linker error] undefined reference to `SDL_LoadBMP_RW'
[Linker error] undefined reference to `SDL_RWFromFile'
[Linker error] undefined reference to `SDL_LoadBMP_RW'
[Linker error] undefined reference to `SDL_UpperBlit'
[Linker error] undefined reference to `SDL_UpperBlit'
[Linker error] undefined reference to `SDL_Flip'
[Linker error] undefined reference to `SDL_Init'
[Linker error] undefined reference to `SDL_GetError'
[Linker error] undefined reference to `SDL_Quit'
[Linker error] undefined reference to `SDL_SetVideoMode'
[Linker error] undefined reference to `SDL_GetError'
[Linker error] undefined reference to `SDL_PollEvent'
[Linker error] undefined reference to `SDL_GetKeyState'
[Linker error] undefined reference to `WinMain@16'

wot does this mean pls?

I am new to c++ but I am learning very quickly.

cheer
it means the linker cannot find the definition of SDL_RWFromFile, ...
i dont use SDL so i dont know where is the SDL library (xxx.lib).
what you need to do is to link the SDL library with compiler (inside the ide), in Dev-Cpp:
Tools->Compiler Options->Directories
and add the directory where the xxx.lib of SDL exists.
you can look for the xxx.lib in the sdl directories, or maybe it is written in some ReadMe text file.
pex.
Project->ProjectOptions->Parameters->Linker->
then in the linker box type
-lmingw32 -lsdlmain -lsdl
thanks but I got just 1 error now which is

C:\Dev-Cpp\Makefile.win [Build Error] [Project1.exe] Error 1

can anyone help me on just 1 error then I get on with doing Image on C++ YAY....


cheer
-mwindows <- don't forget to add this to the linker.
_________________Politics is the ability to foretell what is going to happen tomorrow, next week, next month and next year. And to have the ability afterwards to explain why it didn't happen. -- Winston ChurchillGDNet-0.2 - rate users the easy way with this nifty Firefox extension. Updated with new features.

This topic is closed to new replies.

Advertisement