Jump to content
  • Advertisement
Sign in to follow this  
kaktusas2598

Linker erors in SDLproject

This topic is 2896 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'm creating Pong game in C++ and SDL and I get bunch of linker errors. Here are these errors:



main.obj : error LNK2001: unresolved external symbol __RTC_Shutdown
game.obj : error LNK2001: unresolved external symbol __RTC_Shutdown
main.obj : error LNK2001: unresolved external symbol __RTC_InitBase
game.obj : error LNK2001: unresolved external symbol __RTC_InitBase
game.obj : error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in function "private: bool __thiscall Game::Init(void)" (?Init@Game@@AAE_NXZ)
LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
D:\ProjectsVisualStudio2008\SpacePong\Debug\SpacePong.exe : fatal error LNK1120: 4 unresolved externals

So far I have coded this:

main.cpp

int main(int argc, char *argv[])
{
return 0;
}


game.h

#ifndef GAME_H
#define GAME_H
#include "SDL.h"

enum GameState
{
MENU,
PLAY
};

class Game
{
public:
Game();
~Game();
void Run();
private:
bool Load();
bool Init();

GameState state;
SDL_Surface* screen;
SDL_Surface* background;
SDL_Surface* score;
SDL_Event event;
bool gameIsRunning;

};

#endif


game.cpp

#include "game.h"
#include "constants.h"

Game::Game()
{
screen = 0;
background = 0;
state = MENU;
score = 0;
gameIsRunning = true;
}
bool Game::Init()
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
return false;

screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
if(screen = 0)
return false;

//if everything's OK
return true;
}
void Game::Run()
{
if(!Init())
return;

while(gameIsRunning)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
gameIsRunning = false;
}
}

}


It's not that much, cause i started creating game just today, but these errors is really bugging me, so please help if you know that might be causing this

Share this post


Link to post
Share on other sites
Advertisement
Thanks it helped and i get rid of these errors, but it now shows another 3 linker errors:


SDLmain.lib(SDL_win32_main.obj) : error LNK2005: _main already defined in main.obj
MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol _SDL_main referenced in function _main
D:\ProjectsVisualStudio2008\SpacePong\Debug\SpacePong.exe : fatal error LNK1120: 1 unresolved externals

Share this post


Link to post
Share on other sites
You need to include SDL.h in the source file that defines main(). This is because SDL #defines main to SDL_main, which you need to provide. SDL_main is called by OS specific entry points in SDLmain.lib.

Share this post


Link to post
Share on other sites

You need to include SDL.h in the source file that defines main(). This is because SDL #defines main to SDL_main, which you need to provide. SDL_main is called by OS specific entry points in SDLmain.lib.


Thanks, I never knew that, it works now, but however than i include game.h in main.cpp and create Game object linker throws this error:


MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
main.obj : error LNK2019: unresolved external symbol "public: __thiscall Game::~Game(void)" (??1Game@@QAE@XZ) referenced in function _SDL_main
D:\ProjectsVisualStudio2008\SpacePong\Debug\SpacePong.exe : fatal error LNK1120: 1 unresolved externals

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!