# Error when executing program

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

## Recommended Posts

When I try to execute my program I get the following error message: -------------------- source.cpp Linking... SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_main Debug/tryAgain.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. ----------------------- I have tried to pinpoint what piece of code is causing this error, but now I have almost given up completely. These are the two include files I use in my program: #include <SDL/SDL.h> #include <SDL/SDL_image.h> Can you help me find the reason for this error? Or do you need actual code from my program? (I have not included it here, since I have no idea which code "segments" are causing the error)

##### Share on other sites
The error is a link error. C/C++ uses a compile/link/execute cycle, you haven't quite gotten your program to execute yet [smile].

However, the solution should be quite simple. Just make sure main() is declared as:
int main( int argc, char **argv ) {    // code goes here}

Note that "char *argv[]" is also acceptable in place of "char **argv".

This is due to the way platforms such as windows require a special main function called WinMain(). SDLmain.lib gives you this function, and then calls your main. To do this it maps your "main" to "SDL_main". It does this via a #define in SDL.h, you don't have to do anything. Then SDLmain.lib's WinMain calls your SDL_main. You can see that in the error, SDLmain.lib is complaining because "SDL_main" is not found.

##### Share on other sites

Thanks! Now it works fine.:-)