I'm using Visual Studio 2010 to compile my C++ project, and the linker is barfing on two of my files which have the same name- but they're in completely different directories. How can I make the linker recognize that they are different files?
10
votes
Please give us the exact details, the cause is probably not the fact that they have the same name, rather that they, for example, have a function with the same name or similar.
- Irfy
There's no information here, not even what the error message is. All anyone can do is guess at the problem, and that's a waste of time.
- Carey Gregory
Right-click one of the files, Properties, C/C++, Output Files, change the Object File Name to, say, $(IntDir)\$(InputName)2
- Hans Passant
For the record, the "duplicate" question was asked six months after this one, making that the duplicate.
- Puppy
2 Answers
15
votes
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:
- Use a different output directory (build directory) for each input folder
- 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.
6
votes
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?.