Linker Error =(

Started by
6 comments, last by goonst 18 years, 8 months ago
Sorry if this ends up being a really dumb question, but I'm having a tuff time trying to figure this error out. Below are the two errors I get when I try to compile. Linking... LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup Debug/Poker.exe : fatal error LNK1120: 1 unresolved externals My program compiled just fine, but once I added the following line #include <SDL.h> It started doing this. This was the only change to my code. Any help would be much appreciated. -- Goonst
Advertisement
It sounds like you didn't add the SDLmain.lib file to the list of libararies to be linked.
I threw SDLmain.lib in C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib.

Not sure if the correct way I should be adding this lib though.
It's not. Go to your project properties, linker setting and hit the input section. Add SDLmain.lib and SDL.lib to the Additional Dependencies line.
Even more linker errors unfortunately =(

Linking...
msvcrt.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCD.lib(typinfo.obj)
msvcrt.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCD.lib(typinfo.obj)
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: _strrchr already defined in LIBCD.lib(strrchr.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fgetc already defined in LIBCD.lib(fgetc.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _setvbuf already defined in LIBCD.lib(setvbuf.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
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol _SDL_main referenced in function _main
Debug/Poker.exe : fatal error LNK1120: 1 unresolved externals

Any ideas? I think I may have added setup SDL incorrectly. I threw all the SDL header files in C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include and all the lib files in C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib
SDL defines main() as "int main(int argc, char *argv[])" so make sure your main method matches this otherwise the linker will complain.

Regarding the multiple definition errors, make sure you have your code generation options set to multi-threaded DLL for release build and multi-threaded debug dll for debug builds.
You need to change your project properties to match the SDL library runtime, it's Properties | C/C++ | Code Generation | Runtime Library. I believe you want to set it to Multithreaded DLL.
Sorry for the late reply, That fixed it =). Thank you VERY much for the help guys.

This topic is closed to new replies.

Advertisement