# Unresolved external symbol main?!?

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

## Recommended Posts

I get this error: LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup Yes, I want to be making a console application (because this app has no graphics), yes, I am using Visual C++, and yes, I have defined main...
int main(int argc, char *argv[])
{
...... lots of code
}

Why is it an unresolved external?

##### Share on other sites
I can only think of a few things that could cause this: that main() is in a namespace, that main() is declared static, or that your cpp file is somehow not included in compilation.

##### Share on other sites
Oh, and I forgot to mention that I am using SDL (mainly for SDL_net though), and I'm compiling everything as C code...

##### Share on other sites
ohh, you should have said that before.
the problem is that you shouldnt use int main()
you should use int main(int argc, char *argv[]).
edit:
if this dosent work, do this:
Project->Settings
in the C++ Tab choose the "Code Generation" category, and change the "Use run-time library" to "Mulithreaded DLL"

##### Share on other sites
Yep I know what is wrong I had the same problem :). I forgot to include the libs needed with sdl - sdl.lib and sdlmain.lib as I remember.

##### Share on other sites
Quote:
 Original post by Beer HunterI can only think of a few things that could cause this: that main() is in a namespace, that main() is declared static, or that your cpp file is somehow not included in compilation.

None of these is true, but other posters have said that it is because of SDL...

Quote:
 Original post by Ilanktohh, you should have said that before.the problem is that you shouldnt use int main()you should use int main(int argc, char *argv[]).edit:if this dosent work, do this:Project->Settingsin the C++ Tab choose the "Code Generation" category, and change the "Use run-time library" to "Mulithreaded DLL"

I already am using int main(int argc, char *argv[])

Quote:
 Original post by DMINATORYep I know what is wrong I had the same problem :). I forgot to include the libs needed with sdl - sdl.lib and sdlmain.lib as I remember.

I forgot to include SDLmain.lib, but when I included it, I got other linker errors:

msvcrt.lib(MSVCR71.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fopen already defined in LIBCD.lib(fopen.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/t_c.exe : fatal error LNK1169: one or more multiply defined symbols found

I did the /NODEFAULTLIB:msvcrt.lib and got this:

SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol _exit imported in function _main
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol _strncpy imported in function _main
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol __iob imported in function _ShowError
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol _fopen imported in function _cleanup_output
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol _fclose imported in function _cleanup_output
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol __pctype imported in function _ParseCommandLine
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol ___mb_cur_max imported in function _ParseCommandLine
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol __isctype imported in function _ParseCommandLine
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__strrchr referenced in function _main
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _ShowError
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__remove referenced in function _cleanup_output
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__fgetc referenced in function _cleanup_output
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__setbuf referenced in function _WinMain@16
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__setvbuf referenced in function _WinMain@16
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__freopen referenced in function _WinMain@16
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp___getcwd referenced in function _WinMain@16
Debug/t_c.exe : fatal error LNK1120: 8 unresolved externals

I went back and removed the NODEFAULTLIB, and did the multithreaded DLL thing, and it built successfully... now to test it...

##### Share on other sites

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

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

• ### Forum Statistics

• Total Topics
628722
• Total Posts
2984397

• 25
• 11
• 10
• 16
• 14