Jump to content
  • Advertisement
Sign in to follow this  
Talmir

A little trouble initializing SDL

This topic is 4464 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

Hi :) I hope you can help me. I am trying to get started with SDL in C++ and Visual C++ 2005 express edition. I have this short code: #include "sdl\SDL.h" int main() { SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO); atexit(SDL_Quit); return 0; } Which I think should compile normally but I get these error messages: ------ Build started: Project: SDL_tests, Configuration: Debug Win32 ------ Compiling... main.cpp Linking... main.obj : error LNK2019: unresolved external symbol _SDL_Quit referenced in function "int __cdecl SDL_main(void)" (?SDL_main@@YAHXZ) main.obj : error LNK2019: unresolved external symbol _SDL_Init referenced in function "int __cdecl SDL_main(void)" (?SDL_main@@YAHXZ) LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup C:\Documents and Settings\Kristinn Esmar\My Documents\Visual Studio 2005\Projects\SDL_tests\Debug\SDL_tests.exe : fatal error LNK1120: 3 unresolved externals Build log was saved at "file://c:\Documents and Settings\Kristinn Esmar\My Documents\Visual Studio 2005\Projects\SDL_tests\SDL_tests\Debug\BuildLog.htm" SDL_tests - 4 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Anyone have any idea what is wrong?

Share this post


Link to post
Share on other sites
Advertisement
You have your int main() function declared incorrectly.

For reasons that have been explained to me multiple times that I always forget([smile]), you must create you main() function as:

int main(int argc, char* args[])

Hope that is what you were looking for.

Share this post


Link to post
Share on other sites
I changed it to

int main(int argc, char* args[])

but I still get the exact same errors.

Share this post


Link to post
Share on other sites
Quote:
Original post by Servant of the Lord
You have your int main() function declared incorrectly.

For reasons that have been explained to me multiple times that I always forget([smile]), you must create you main() function as:

int main(int argc, char* args[])

Hope that is what you were looking for.


SDL does some funky name mangling so that your main becomes SDL_main and SDL actually does your main... So if you don't do (int, char**) SDL won't know to replace it and thus would give errors.

Also, did you link to SDL.lib and SDLmain.lib:

#pragma comment(lib, "SDLmain.lib")
#pragma comment(lib, "SDL.lib")

// at the very top

Share this post


Link to post
Share on other sites
Yes you must change your main function. If those same error messages come up then...it seems like some stuff is linked wrong. Check how you are linking them There are 2 possible mains. They are as followed:


int main(int argc, char* argv[]);
...
//or
int main(int argc, char** argv);




I hope that helps.

Chad.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I've changed the category to multithreaded dll, told it not to use precompiled headers and changed the code to this:

#include "SDL.h"

int main( int argc, char* args[] )
{ //Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}

now I only get one error...

LINK : fatal error LNK1561: entry point must be defined

Doesnt seem to work :*(

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
I've changed the category to multithreaded dll, told it not to use precompiled headers and changed the code to this:

#include "SDL.h"

int main( int argc, char* args[] )
{ //Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}

now I only get one error...

LINK : fatal error LNK1561: entry point must be defined

Doesnt seem to work :*(


Did you add the #pragmas like I said above?

Share this post


Link to post
Share on other sites
yeah, it didnt change anything.. I also tried putting the libs in as additional dependencies.

Share this post


Link to post
Share on other sites
Ahh.. I started a new application... The earlyer one was an empty one.. Now I started a console app (win32) and it works when I add the libs as dependancies. Thanks guys for your help :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!