VisualStudio project with multiple sourcefiles of the same name?

You can set a file-specific project setting for one (or both) of the files that conflict and set the "Object File Name" property to:

$(InputDir)\$(IntDir)\

Just right-click the filename instead of the project name to set the property for that file only.

For example, if you do that for \MyProject\foo\File.cpp then the object file for that source file will go to \MyProject\foo\Release\File.obj so it won't conflict with the object file for \MyProject\bar\File.cpp.

The drawbacks to this are that it can clutter your source tree with compiler outputs (but hopefully there aren't too many), and - even worse - file-specific project settings tend to get forgotten/hidden since they're not called out in the IDE at all. If sometime down the road you (or someone else) needs to change things, it can be quite a mystery about why the build acts so strangely for particular files until someone screws around with it for a half a day until it dawns on them what's going on.

I would personally prefer that a project-wide setting of $(InputDir)\$(IntDir)\ would cause object files to go to directories relative to the source file, but it actually doesn't work well at all as a project level setting. In that case VS still only sets the output directory once and it ends up being relative to the first source file in the list. Then the linker gets confused about where it should look for object files.


Maybe you can set the project wide 'object file name' (Configurtion Properties->C/C++->Output Files) to

$(IntDir)%(RelativeDir)

which uses the relative source folder of the source files. Note the %, but this gets ugly if your source files are located out of your project directory, containing ..\