Unwarranted LNK2001 Errors

I’ve sometimes struggled with a recurring phantom linker error. Linker errors which insist that certain functions are missing, when they are clearly present in the project, and I can see they are being compiled.

There are many common reasons for this error, but here’s another one, I had to figure out for myself:
If you have a visual studio project with multiple files of the same name, but on different sub-paths (for example functions/color.cpp and types/color.cpp), they may both be compiled to color.obj in the temporary output dir (this may only happen because I have customized my output dir, but I am not sure). For some odd reason, this doesn’t cause a problem most of the time (me anyway), but then, sometimes it does.

To see whether this is happening to you: Compile, observe the linker error happening, and then go into your intermediate files dir, and use the tool dumpbin.exe to dump the symbols of the object file:

dumpbin /SYMBOLS color.obj

Then see whether the names are only for the color.cpp for which you aren’t getting linker errors.

The solution is to either manually specify a different output path for one of those files, or to change the name of one of the files.
It goes to show that it’s a bad idea to have multiple files in your project with same filename.

To use dumpbin.exe you might need to include these paths in your PATH:

C:\\Program Files\\Microsoft Visual Studio 8\\VC\\bin
C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE