Sign in to follow this  

Can't figure out where these errors are comming from.

This topic is 4758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
#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;
}

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
You changed:


#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?

Share this post


Link to post
Share on other sites
Have you linked sdl.lib and sdlmain.lib?

Also, I sometimes get that first warning in SDL projects, even though I've set my project to use multithreaded DLLs. I haven't actually had any problems though.

Edit: It turns out I'm blind. You did link both libraries. Are both libraries actually copied into the right place? I would assume so, since there are no errors finding them.

Share this post


Link to post
Share on other sites

This topic is 4758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this