#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#include <iostream>
#include <SDL.h>
using namespace std;
// animation struct
struct CAnimation
{
int frameCount;
int x;
int y;
int w;
int h;
};
// sprite class
class CSprite
{
private:
CAnimation animation;
int xpos;
int ypos;
public:
void SpriteInit();
void ChangeFrame();
void DrawFrame(SDL_Surface *screen, SDL_Surface *frame);
};
// Initializes the sprite
void CSprite::SpriteInit()
{
CSprite::animation.frameCount = 0;
CSprite::animation.x = 0;
CSprite::animation.y = 0;
CSprite::animation.w = 63;
CSprite::animation.h = 63;
CSprite::xpos = 300;
CSprite::ypos = 300;
}
// Changes the frame
void CSprite::ChangeFrame()
{
CSprite::animation.frameCount++;
CSprite::animation.x += 63;
}
// Draw the frame
void CSprite::DrawFrame(SDL_Surface *screen, SDL_Surface *frame)
{
SDL_Rect dest;
dest.x = CSprite::xpos;
dest.y = CSprite::ypos;
SDL_Rect source;
source.x = CSprite::animation.x;
source.y = CSprite::animation.y;
source.w = CSprite::animation.w;
source.h = CSprite::animation.h;
SDL_BlitSurface(frame, &source, screen, &dest);
SDL_Flip(screen);
}
int main(char argc, char *argv[])
{
CSprite sprite;
// set up sdl
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
cout << "Error in initalizing SDL: " << SDL_GetError() << "\n";
exit(1);
}
atexit(SDL_Quit);
// create surfaces
SDL_Surface *screen;
SDL_Surface *frame;
SDL_Surface *background;
screen = SDL_SetVideoMode(600, 600, 24, SDL_HWSURFACE|SDL_DOUBLEBUF);
// make sure screen was made
if(screen == NULL)
{
cout << "Could not create screen: " << SDL_GetError() << "\n";
exit(1);
}
// load images
frame = SDL_LoadBMP("dfly.bmp");
background = SDL_LoadBMP("background.bmp");
// draw the background
SDL_Rect backdest;
backdest.x = 0;
backdest.y = 0;
SDL_BlitSurface(background, NULL, screen, &backdest);
// game loop
bool done = false;
while(done == false)
{
// for events
SDL_Event event;
// event loop
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
done = true;
}
if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym == SDLK_ESCAPE)
{
done = true;
}
}
}
sprite.SpriteInit();
sprite.DrawFrame(screen, frame);
SDL_Delay(1000);
sprite.ChangeFrame();
}
return 0;
}
Can't figure out where these errors are comming from.
I am getting the following errors from my sdl experiment project. I just can't find where they are comming from.
AnimationExperiment warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
AnimationExperiment error LNK2019: unresolved external symbol _SDL_main referenced in function _main
AnimationExperiment fatal error LNK1120: 1 unresolved externals
here is the code
Did you try setting /NODEFAULTLIB:library in the linker options? Guessing here... but it sounds like you have a library that already statically links in msvcrt.lib... which is different to what is trying to be linked in here by default.
So, if you set /NODEFAULTLIB:library... it won't do the link...
Just a guess...
So, if you set /NODEFAULTLIB:library... it won't do the link...
Just a guess...
nvm what was here b4 I am still at these errors.
AnimationExperiment warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
AnimationExperiment error LNK2019: unresolved external symbol _SDL_main referenced in function _main
AnimationExperiment fatal error LNK1120: 1 unresolved externals
I should not have to disable default libraries because all my other sdl apps work file with the default libraries enabled.
[Edited by - TheNobleOne on December 2, 2004 5:44:22 PM]
AnimationExperiment warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
AnimationExperiment error LNK2019: unresolved external symbol _SDL_main referenced in function _main
AnimationExperiment fatal error LNK1120: 1 unresolved externals
I should not have to disable default libraries because all my other sdl apps work file with the default libraries enabled.
[Edited by - TheNobleOne on December 2, 2004 5:44:22 PM]
It sounds like you're still linking to something (lib or dll) that uses the multi-threaded debug libs. If you haven't done a clean/rebuild, try that (if you have incremental linking on msvc doesn't always catch changes to libs). Otherwise either chance you project to use the mtd libs as well, or track down what's using it.
Ok I am back to the first 3 errors again. turns out I am suppose to use the multithreaded debug dll switch. However, I can't find why I have 3 those errors.
The warning should have disappeared when you switched your project to use the multithreaded DLLs. Are you sure you did it properly?
The two errors are actually one problem being reported twice; it's a tricksy result of the way SDL does it's platform-independent code. Let me explain...
Because the entry point on a Windows app needs to be called 'WinMain,' as opposed to other platforms that usually just want 'main,' SDL hides the difference by providing WinMain/main for whichever platform you're using and having it call through to your own function (which is *always* called 'main'). That way you can just write 'main,' compile it on either platform, and SDL takes care of the incompatability in names.
However, you can't actually call it 'main' because (on many platforms) SDL is already providing a function with that name on non-Windows platforms [smile]
So, what it does is to provide a header file - sdl_main.h - which, when included, replaces the word 'main' with '_SDL_main' - so your function which appears to be called main() actually reaches the compiler as _SDL_main(). It doesn't have a problem with that; a name's a name, as far as it's concerned. SDL's own WinMain/main function thus includes a call to _SDL_main().
The problem is that you've not included the sdl_main.h header here, so your main() function isn't getting renamed. When the linker tries to connect the SDL library (which has a call to _SDL_main()) to your code (which isn't providing an _SDL_main()) function, it complains. That's what 'unresolved external' means - a function that the SDL library makes to outside of itself (i.e. an 'external' call) couldn't be found around anywhere else.
Including sdl_main.h should fix the problem; or, if you want, you could rename your main function to _SDL_main. Including sdl_main.h is the recommended approach, though.
The two errors are actually one problem being reported twice; it's a tricksy result of the way SDL does it's platform-independent code. Let me explain...
Because the entry point on a Windows app needs to be called 'WinMain,' as opposed to other platforms that usually just want 'main,' SDL hides the difference by providing WinMain/main for whichever platform you're using and having it call through to your own function (which is *always* called 'main'). That way you can just write 'main,' compile it on either platform, and SDL takes care of the incompatability in names.
However, you can't actually call it 'main' because (on many platforms) SDL is already providing a function with that name on non-Windows platforms [smile]
So, what it does is to provide a header file - sdl_main.h - which, when included, replaces the word 'main' with '_SDL_main' - so your function which appears to be called main() actually reaches the compiler as _SDL_main(). It doesn't have a problem with that; a name's a name, as far as it's concerned. SDL's own WinMain/main function thus includes a call to _SDL_main().
The problem is that you've not included the sdl_main.h header here, so your main() function isn't getting renamed. When the linker tries to connect the SDL library (which has a call to _SDL_main()) to your code (which isn't providing an _SDL_main()) function, it complains. That's what 'unresolved external' means - a function that the SDL library makes to outside of itself (i.e. an 'external' call) couldn't be found around anywhere else.
Including sdl_main.h should fix the problem; or, if you want, you could rename your main function to _SDL_main. Including sdl_main.h is the recommended approach, though.
You changed:
to
and still get exactly the same errors?
#include <iostream>#include <SDL.h>using namespace std;
to
#include <iostream>#include <SDL.h>#include <SDL_main.h>using namespace std;
and still get exactly the same errors?
from what i've seen from everyone else's code, i thought you included SDL files like this:
or is that for something else?
#include <SDL/SDL.h>#include <SDL/SDL_main.h>
or is that for something else?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement