HelloWorld using SDL HELP!!!
Please help,
I try to get the HelloWorld work. I put the SDL.dll in the debug folder. But I got the errors as following.
____ERRORSSSSSSSS________
1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
1>Linking...
1>test.obj : error LNK2019: unresolved external symbol _SDL_Quit referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_UpdateRect referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_UpperBlit referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_PollEvent referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_FreeSurface referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_LoadBMP_RW referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_RWFromFile referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_WM_SetCaption referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_SetVideoMode referenced in function _SDL_main
1>test.obj : error LNK2019: unresolved external symbol _SDL_Init referenced in function _SDL_main
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\...\projects\HelloWorld\Debug\HelloWorld.exe : fatal error LNK1120: 11 unresolved externals
1>Build log was saved at "file://c:\Users\..\projects\HelloWorld\HelloWorld\Debug\BuildLog.htm"
1>HelloWorld - 12 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
/**
* This source code is part of the samples for "Game Programming in C++: Start to Finish".
*
* This example SDL code will load up a bitmap image of the SDL logo, and just display
* it in a window for you. It's very bare bones.
*
* @Author : Erik Yuzwa
* @Date : 09/01/2005
* @Version: 1.0
*/
#include <SDL.h>
int main(int argc, char* argv[])
{
//initialize SDL and the video subsystem
if(SDL_Init( SDL_INIT_VIDEO ) < 0)
return -1;
//create an SDL_Surface object which represents the
//game window
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 0, 0);
//signal SDL to change the text of the main window
//to "Hello World"
SDL_WM_SetCaption("Hello World", "Hello World");
//load the SDL logo bitmap to a temporary surface
SDL_Surface* temp = SDL_LoadBMP("sdl_logo.bmp");
//create the working SDL_Surface which matches the
//display format of the temporary surface
SDL_Surface* bg = NULL; //SDL_DisplayFormat(temp);
//free the memory allocated to the temporary SDL_Surface
SDL_FreeSurface(temp);
SDL_Event event;
bool quit = false;
//This is the main message loop of the game
while(!quit)
{
//check the message queue for an event
if (SDL_PollEvent(&event))
{
//if an event was found
switch (event.type)
{
//check to see if the window was closed via the "x button"
case SDL_QUIT:
//set the quit flag to true
quit = true;
break;
//check the keyboard to see if the ESC key was pressed
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
//set our quit flag to true
quit = true;
break;
}
break;
}
}
//draw the background sprite
SDL_BlitSurface(bg, NULL, screen, NULL);
//update the current window
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
//free the allocated memory for the background surface
SDL_FreeSurface(bg);
//quit SDL and allow it to clean up everything
SDL_Quit();
//return control to Windows with no errors
return 0;
}
Thanks!!
I did the linkers after your suggestion. The HelloWorldWindow displays. But it does display the sdl_logo.bmp. I copied the image into the project folder, debug folder, every folder the project has. It does not load the image at all.
Please help again. Thanks in advance!!
I did the linkers after your suggestion. The HelloWorldWindow displays. But it does display the sdl_logo.bmp. I copied the image into the project folder, debug folder, every folder the project has. It does not load the image at all.
Please help again. Thanks in advance!!
//load the SDL logo bitmap to a temporary surfaceSDL_Surface* temp = SDL_LoadBMP("sdl_logo.bmp");//create the working SDL_Surface which matches the//display format of the temporary surfaceSDL_Surface* bg = NULL; //SDL_DisplayFormat(temp);//free the memory allocated to the temporary SDL_SurfaceSDL_FreeSurface(temp);
You're freeing the temp surface right after you load it, and plus you aren't drawing/blitting it onto the screen:
//draw the background spriteSDL_BlitSurface(bg, NULL, screen, NULL);//draw temp //SDL_BlitSurface(temp, NULL, screen, NULL);//update the current windowSDL_UpdateRect(screen, 0, 0, 0, 0);
Also, if you suspect that you're image isn't loading correctly, you can check to see if Load_BMP fails:
//load the SDL logo bitmap to a temporary surfaceSDL_Surface* temp = SDL_LoadBMP("sdl_logo.bmp");if ( temp == 0 ) return -1;
Quote:But it does display the sdl_logo.bmp.Did you mean 'it doesn't display the sdl_logo.bmp'?
Just a little tip, the project folder is basically considered the relative root folder for directories. The debug and release(when you select to compile a release build for a final build) folders should not be used to store resources in even though the compiled .exe file ends up in there. Take the .exe out of there and move it to the project folder when you want to distribute it your project with an executable.
If you see a lot space being taken up by project folders and you know you don't have many resources in there you can go ahead and delete those folders, you'll just have to recompile them if you don't grab the .exe file out of there first.
If you see a lot space being taken up by project folders and you know you don't have many resources in there you can go ahead and delete those folders, you'll just have to recompile them if you don't grab the .exe file out of there first.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement