Two files of the same name give linker error in Visual Studio

I believe the problem comes from the fact that all your .obj files are written to the same folder, and so the outputs from compiling those two source files are colliding. I think there are at least two possible solutions:

  1. Use a different output directory (build directory) for each input folder
  2. Create custom object file names for each (or just one) of your source files

I'm not certain about the first option, but for the second, you should be able to right-click the source file in the solution explorer, select "Properties", and find some configuration setting to over-ride the output (.obj) file created for that source file.


Use $(IntDir)%(RelativeDir) in "Object File Name" property

(Configuration Properties -> C/C++ -> Output Files -> Object File Name)

  • of project, OR
  • of .cpp file.

This is an answer from the related question VisualStudio project with multiple sourcefiles of the same name?.