c++visual-c++codeblocks

C++: error LNK2019: unresolved external symbol __snprintf referenced in function


I'm trying to compile a project but I'm getting this error:

1>project.obj : error LNK2019: unresolved external symbol __snprintf referenced in function "unsigned char * __cdecl GetResource(char *,unsigned long &)" (?GetResource@@YAPAEPADAAK@Z)
1>Release/file.bin : fatal error LNK1120: 1 unresolved externals

I'm using VC++ 2010 and also tried compiling with CodeBlocks, but getting a similar error:

windres.exe  -J rc -O coff -i C:\Users\x\Desktop\project\project\File.rc -o .objs\File.res
windres.exe: no resources
Process terminated with status 1 (0 minutes, 0 seconds)

I have File.rc in my project directory but it's 0kb, I have no idea how to fix this.

I'm pretty sure this is not related to something in the code so I did not post a sample, but if you require one, I'll post it.


Solution

  • Linker errors are generated due to how c++ and many other similar languages compile and link code. The compiler generates object files (*.obj) and only requires function declarations in order to compile code that calls these functions- that's why forward declarations and header files work. After compilation, at link time, the linker looks for the definitions of these functions in compiled files (usually in object files (*.obj) or libraries (*.lib). A linker error saying "Unresolved external symbol" means a declaration without matching definition has been used. Most often this is because of a spelling error in the declaration or definition, or because the file containing the definition was never linked.

    Long story short, you are missing a reference to a library. That might be libcmt.lib for release and libcmtd.lib for debug.