Help installing SDL

I was following Lazy Foo’s tutorial for getting started with SDL.
http://lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/msvsnet2010u/index.php
So I followed all the instructions on the page(and even used the source code in lesson 1), I get the compilation error.

Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup C:\Users\Minkai\Documents\Visual Studio 2013\Projects…\MSVCRTD.lib(crtexe.obj)

I searched around the internet and someone said I can bypass that by adding
#undef main

I tried that and now the compiler doesn’t recognize things like SDL_Init(SDL_INIT_VIDEO), SDL_CreateWindow… etc, although it still recognizes things like SDL_Window, SDL_Surface. Here’s the source code:

Code:
#include
#include <SDL.h>
#undef main

int main(int argc, char *argv[]){
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
return 1;
}
SDL_Quit();

return 0;

}

Error 1 error LNK2019: unresolved external symbol _SDL_GetError referenced in function _main
Error 2 error LNK2019: unresolved external symbol _SDL_Init referenced in function _main
Error 3 error LNK2019: unresolved external symbol _SDL_Quit referenced in function _main
Error 4 error LNK1120: 3 unresolved externals

I’ve double checked to make sure the Include Directories and Library Directories are fine. Linker > Input > Additional Dependencies are fine too. For Linker > System > SubSystem, I tried switching between Window and Console, doesn’t work. I put my SDL2.dll everywhere in the project to make sure.

Please help.

Some information:

  1. Using the latest SDL SDL2-devel-2.0.3-VC.zip
  2. IDE is Microsoft Visual Studio Express 2013 for Windows Desktop
    Version 12.0.31101.00 Update 4
  3. OS is 64-bit Windows 8.1

Can somebody please help? I have no idea what is wrong.

Error 1 error LNK2019: unresolved external symbol _main referenced in
function ___tmainCRTStartup C:\Users\Minkai\Documents\Visual Studio
2013\Projects…\MSVCRTD.lib(crtexe.obj)

Are you building a console app instead of a Windows app by accident?
Make sure you:

  • Build with /SUBSYSTEM:WINDOWS
  • link against SDLmain.lib (which provides WinMain())
  • have a main() function in your program in a source file that #include
    SDL.h" (which will make the right function for WinMain() to call).

–ryan.

I will second what Ryan said, not because he knows what he’s talking about,
but because I was writing a much longer-winded version of this and realized
it was unnecessary.

-AlexOn Mon, Feb 9, 2015 at 3:27 PM, Ryan C. Gordon wrote:

Error 1 error LNK2019: unresolved external symbol _main referenced in

function ___tmainCRTStartup C:\Users\Minkai\Documents\Visual Studio
2013\Projects…\MSVCRTD.lib(crtexe.obj)

Are you building a console app instead of a Windows app by accident? Make
sure you:

  • Build with /SUBSYSTEM:WINDOWS
  • link against SDLmain.lib (which provides WinMain())
  • have a main() function in your program in a source file that #include
    SDL.h" (which will make the right function for WinMain() to call).

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

*not just because he knows

Had a weird inclination to re-read my post, and sure enough, the words
didn’t come out just right.On Mon, Feb 9, 2015 at 3:29 PM, Alex Barry <@Alex_Barry> wrote:

I will second what Ryan said, not because he knows what he’s talking
about, but because I was writing a much longer-winded version of this and
realized it was unnecessary.

-Alex

On Mon, Feb 9, 2015 at 3:27 PM, Ryan C. Gordon wrote:

Error 1 error LNK2019: unresolved external symbol _main referenced in

function ___tmainCRTStartup C:\Users\Minkai\Documents\Visual Studio
2013\Projects…\MSVCRTD.lib(crtexe.obj)

Are you building a console app instead of a Windows app by accident? Make
sure you:

  • Build with /SUBSYSTEM:WINDOWS
  • link against SDLmain.lib (which provides WinMain())
  • have a main() function in your program in a source file that #include
    SDL.h" (which will make the right function for WinMain() to call).

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ryan C. Gordon wrote:

Error 1 error LNK2019: unresolved external symbol _main referenced in
function ___tmainCRTStartup C:\Users\Minkai\Documents\Visual Studio
2013\Projects…\MSVCRTD.lib(crtexe.obj)

Are you building a console app instead of a Windows app by accident?
Make sure you:

  • Build with /SUBSYSTEM:WINDOWS
  • link against SDLmain.lib (which provides WinMain())
  • have a main() function in your program in a source file that #include
    SDL.h" (which will make the right function for WinMain() to call).

Hello Ryan, on the second note did you mean SDL2main.lib? If yes I still can’t figure out what is wrong. Here are my settings again.
[Image: https://xccycw-ch3302.files.1drv.com/y2px5V8Dj3hmllE7ri15oipTSY4R1DW74pUCkFPwFqFgTbTNOy4BcSaawsy2YLuhPJc93XtAvobgQVCDiOTnR-tilQQ9NIsf8cy5QI3SkEHyebs0EmItLCn2w305If80I5h8XWLaXe0NGIIIftPpk4_Sw/SDLerror1.jpg ]
[Image: https://xmcycw-ch3302.files.1drv.com/y2pB3SVvjYTGPHC6vgJzxWENSxjd9oiegyaD5u4J6hpPrJb4xL7lUlWxXhd-8872M0TOIkf0ZyqZdOwbjBTyyl5BN2f5cfb6DsBGpThwlHllg3fp9gmsXTMmGqWyCtCUr-O7vqXZtmkkteIporXN6tNYg/SDLerror2.jpg ]
[Image: https://w8cycw-ch3302.files.1drv.com/y2peAtaisscGBc3zCMkTzdpemaaO4HK65QHQrppSH_qowKvK6Sz09QGwvdfGs6VeFovs-f0zUCv6ii8RKyS0WSJiYubZSGGkM73lczQn_L51qiepSrvu7wye5b3T6k4x7w3XGxg388tNxhPMCFGDB4MgA/SDLerror3.jpg ]
[Image: https://xscycw-ch3302.files.1drv.com/y2pBJjC9T3ArAUKN8mR2AS6wY8b_jma8ofTqsGmuTiWQ0LEs4EG5glZVqqwKtYlE01_Tv3dafPDmiqu_PvsPfMdOWKMxPLnzhYsVT-KblsDILzxWeeEo0JwAqWq0ZkL3Ar0Ol-6roLw8hR19VDvm4GEXQ/SDLerror4.jpg ]

Problem solved. Solution is to use x86 library and x86 SDL2.dll, even though OS is 64 bit.

… if you’re actually building a 32bit (Win32, not Win64) executable, yeah.

Cheers,
DanielOn 02/20/2015 03:57 AM, fxgbdfg wrote:

Problem solved. Solution is to use x86 library and x86 SDL2.dll, even
though OS is 64 bit.